Repository navigation
fix(binding-kafka): restart api client reconnect back-off after a connection opens - #3268
Merged
Merged
Conversation
…a connection opens Twelve requests are queued on one api client with client.reconnect of 1s. Each of the first eleven connections is aborted by the server while its request is in flight, so the client reconnects with a back-off each time. The twelfth connection answers. With the back-off restarting after each opened connection every reconnect waits 50ms; with the counter never reset the delays grow 50, 100, 200, 400, 800 then 1000ms and the scenario exceeds the five second limit of the existing IT class. Refs #3256 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoYEX7orynKcJ3dSiXi
… delay Run the scenario with the default client.reconnect of 5s and eight queued requests, so seven connections are aborted while a request is in flight and the eighth answers. The engine signaler fires on a 512ms timer wheel, so a cap of 1s could not separate a restarted back-off from a growing one within the five second limit of the IT class. Refs #3256 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoYEX7orynKcJ3dSiXi
…nection opens KafkaApiClient incremented reconnectAttempt on every reconnect and never reset it, so after an outage the back-off of a later reconnect carried on from where the earlier one ended. Reset it when the initial side of a connection first opens, as the cache client fetch and produce streams do. Fixes #3256 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoYEX7orynKcJ3dSiXi
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.
Description
The
reconnectAttemptcounter of the API client inKafkaClientApiFactoryis incremented on every reconnect (50 << reconnectAttempt++, capped byclient.reconnect) and was never reset. The client is long-lived (cached per affinity), so after an outage the back-off of a later reconnect carried on from where the earlier one ended instead of starting again.The counter is now reset when the initial side of a connection first opens (first window in
onNetWindow). This mirrors how the cache client fetch stream (KafkaCacheClientFetchFactory,onClientFanoutInitialWindow) and the cache client produce stream (KafkaCacheClientProduceFactory,onClientFanInitialOpened) reset their ownreconnectAttempt; the cache server fetch, meta, describe and produce streams do the same.Scenario
create.topics.v7.reconnect.backoff.reset(paired app and net scripts, in the existingKafkaCreateTopicsITclasses): eight requests are queued on one API client with the defaultclient.reconnectof 5 s; the first seven connections are aborted by the server while their request is in flight, the eighth answers.Test evidence
The evidence is timing-based. The engine signaler fires on a 512 ms timer wheel (
EngineWorker:new DeadlineTimerWheel(MILLISECONDS, ..., 512, 1024)), so a back-off of 50 ms costs one tick (about 0.5 s), and a restarted and a growing back-off only separate once the growing one passes a tick. The scenario is sized for that, against the existing 5 sTimeoutof the IT class (which covers the test body, not engine and k3po start-up):The body times are the reported test time less about 1.7 s of start-up overhead (measured with a 3 s limit), so they are estimates; the pass/fail results are measured. With a debug print of the computed back-off (not committed) the fixed code scheduled every reconnect with
reconnectAttempt = 0. The same scenario withclient.reconnect=0(which skips the back-off) passes on the unfixed code, so the scripts themselves are sound. The first commit's test (1 s cap, 12 streams) could not separate the two within the limit because of the tick, so the second commit re-sizes it; commit 1 failed with and without the fix and is superseded.Verified with checks on and the build cache skipped:
specs/binding-kafka.spec:clean install, 226 unit tests, 24 stream ITs (network and applicationKafkaCreateTopicsITincluding the new method), build successruntime/binding-kafka:clean verify, 229 unit tests and 462 ITs, 0 failures, 67 skipped (existing skips), build success;KafkaCreateTopicsIT16 tests, 0 failureslicense:formatandcheckstyle:checkcleanKafka protocol text
Read myself: the Apache Kafka protocol documentation page (kafka.apache.org/44/design/protocol), the opening of the Network section and the error-code table; I searched the whole page text for "back-off" and "reconnect" and found neither. I did not read the rest of the page (API key tables and message schemas) in full; the request and response frames in the scripts are copied from the existing
create.topics.v7scripts, not newly derived.The protocol text says nothing about reconnect back-off; this is a client-side policy, and the change only makes it consistent with the other reconnecting streams of this binding.
Not delivered
Fixes #3256
Generated by Claude Code