Repository navigation
Fix consumer poll busy-loop and callback leak when broker is unresponsive - #3186
Open
utku0dogan wants to merge 1 commit into
Open
utku0dogan wants to merge 1 commit into
utku0dogan wants to merge 1 commit into
Conversation
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.
Fixes #3183
When a broker stops answering while keeping TCP connections open (e.g. a paused container or silent network blackhole),
KafkaConsumer.poll()previously entered a tight CPU-bound loop and leaked memory untilrequest_timeout_msexpired:poll_timeout_ms == 0): Onceheartbeat_interval_mselapsed while an in-flightHeartbeatRequest(or async auto-commit) was still waiting on the unresponsive broker,coordinator.time_to_next_poll()continuously returned0, clampingpoll_timeout_ms = 0inKafkaConsumer._poll_onceand callingFetcher.fetch_records(timeout_ms=0)thousands of times per second.Fetcher.fetch_recordsnorNetBackend.await_fordetached its temporary wakeup callbacks from still-pending futures upon timeout, retaining_wake -> wakeup -> wrapper -> KafkaTimeoutError.__traceback__closures on long-lived in-flightFutureinstances across every timed-out wait.Changes
Future._remove_cb_eb(cb, eb)to detach(callback, errback)pairs under a single lock acquire if the future is still pending.finallyblocks inFetcher.fetch_recordsandNetBackend.await_forwhen waited futures have not yet resolved.Heartbeat.heartbeat_in_flightsoBaseCoordinator.time_to_next_heartbeat()returnsheartbeat_interval_ms / 1000instead of0while a heartbeat request is already in flight.coordinator.time_to_next_poll()deadlines toretry_backoff_msinKafkaConsumer._poll_once(aftercoordinator.poll()has already run), while preserving non-blockingpoll(timeout_ms=0)semantics.