Fail permit-based operations with ConsumerShutdownException after consumer termination - #1517
Open
tiagomota wants to merge 1 commit into
Open
Fail permit-based operations with ConsumerShutdownException after consumer termination#1517tiagomota wants to merge 1 commit into
tiagomota wants to merge 1 commit into
Conversation
Contributor
|
Tick the box to add this pull request to the merge queue (same as
|
…sumer termination
tiagomota
force-pushed
the
fix/with-permit-shutdown
branch
from
September 3, 2026 17:53
0d4c412 to
faba152
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Once the background consumer fiber has died (any exception thrown by
poll), the permit-based operationssubscribe,unsubscribeandassignblock forever.withPermitoffers aRequest.WithPermitto the requests queue and then waits on aDeferredthat nothing will ever complete, because the actor loop that services the queue is gone.The
requesthelper used by the commit path already handles this case by racingawaitTermination, so committing on a dead consumer fails fast withConsumerShutdownExceptionwhile unsubscribing on one hangs forever. That shutdown guarantee dates back to #66 ("All KafkaConsumer requests now check to ensure the consumer has not already shutdown") and was lost for the permit-based operations introduced in #906.Why it matters
The idiomatic place to call
unsubscribeis aResource/bracketfinalizer around the record stream. fs2 runs finalizers before surfacing the stream's error, and finalizers are uncancelable. So when the poll loop dies (for example an out-of-range fetch underAutoOffsetReset.None):awaitTermination,unsubscribedeadlocks,.timeout, fiber cancel orIO.racecan fire either.Fix
Mirror the
requesthelper's race inwithPermit:Behaviour matches the commit path: if the fiber died with an error,
awaitTerminationrethrows it; if the consumer terminated normally, the operation fails withConsumerShutdownException. Live consumers are unaffected, the deferred wins the race.