-
Notifications
You must be signed in to change notification settings - Fork 23
Answer every rebalance callback raised during shutdown #2835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
delthas
wants to merge
1
commit into
improvement/BB-833/stop-consuming-on-shutdown
from
improvement/BB-833/answer-rebalance-callbacks
+61
−8
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -819,10 +819,29 @@ class BackbeatConsumer extends EventEmitter { | |
| if (err.code === kafka.CODES.ERRORS.ERR__ASSIGN_PARTITIONS) { | ||
| this._log.info('rdkafka.assign', { assignment }); | ||
|
|
||
| if (!this._shuttingDown) { | ||
| this._setDrain(null); | ||
| // close() has already handed the partitions back. Accepting a | ||
| // fresh grant now leaves the client holding an assignment the | ||
| // disconnect has to revoke all over again, which wedges it and | ||
| // costs us the LeaveGroup the shutdown exists to send. | ||
| if (this._shuttingDown) { | ||
| // assign() is refused once disconnect() has started -- the | ||
| // binding gates it on isConnected(), which is already false -- | ||
| // while unassign() is explicitly permitted while closing, and | ||
| // librdkafka coerces an assign into a full unassign during | ||
| // termination anyway. Leaving the callback unanswered is what | ||
| // parks the client in the rebalance. | ||
| this._bestEffort('assign.declined', () => { | ||
| try { | ||
| this._consumer.assign([]); | ||
| } catch (e) { // eslint-disable-line no-unused-vars | ||
| this._consumer.unassign(); | ||
| } | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| this._setDrain(null); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should not be needed, c.f. first PR in the stack: a new assign cannot happen during an earlier unassign, so setDrain should stay managed in a single place (during partition revoke). |
||
|
|
||
| try { | ||
| this._consumer.assign(assignment); | ||
| if (this._circuitBreaker.state !== BreakerState.Nominal) { | ||
|
|
@@ -841,10 +860,16 @@ class BackbeatConsumer extends EventEmitter { | |
| ledger: this._offsetLedger.getProcessingCount(this._topic), | ||
| }); | ||
|
|
||
| // close() owns the departure: it drains, then un-assigns, which | ||
| // is what answers this revoke. Releasing here would cut that drain | ||
| // short and strand the offsets it exists to commit. | ||
| // librdkafka requires every rebalance callback to be answered, | ||
| // and leaving this one to close() is not enough: a revoke raised | ||
| // after close() has already un-assigned has nothing left to answer | ||
| // it, so the client stays in the rebalance and the disconnect | ||
| // wedges on it. Answering here does not cut the drain short -- | ||
| // close() still waits for the in-flight work, the partitions are | ||
| // simply given back sooner. | ||
| if (this._shuttingDown) { | ||
| this._bestEffort('unassign.shutdown', | ||
| () => this._consumer.unassign()); | ||
| KafkaBacklogMetrics.onRebalance( | ||
| this._topic, this._groupId, unassignStatus.SHUTDOWN); | ||
| return; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
based on this, shoud we not just always call
unassign()in that case, instead of trying toassign([])first?