Repository navigation
fix(binding-kafka): refresh the broker table before answering an unknown broker id - #3232
Merged
jfallows merged 4 commits intoNov 15, 2026
Conversation
* feat(common-json): mark and rewind the generator A generator can mark its position between writes and rewind to it, which discards the bytes written since and restores the structural context, so a unit of output can be generated, measured and then kept or taken back and generated again. This is the output-side counterpart of the parser mark and rewind. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoUTvQwZM7nY1gjgnZJ * refactor(common-json): require every generator to support mark and rewind The generator mark and rewind are declared without a default, as JsonGeneratorImpl is the one implementation of JsonGeneratorEx and supports both. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoUTvQwZM7nY1gjgnZJ * test(common-json): rewind the generator that escapes its output Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoUTvQwZM7nY1gjgnZJ --------- Co-authored-by: Claude <[email protected]>
…s answered A raw API request stream addressed to a non-zero broker id that the route's table does not know triggers an immediate Metadata refresh, and is answered with the existing reset only after that refresh has completed or failed. There is no retry, even when the refreshed table now contains the id. The network scripts for the unknown id now play a second Metadata exchange before the reset. New paired scripts cover a refresh whose response lists the id (still reset, no connection to that broker) and a refresh that fails (the meta connection is aborted). The application pairs for the same two scenarios carry the refreshed partitions on the meta stream. The spec network and application ITs and the runtime IT gain one method per scenario. The runtime scenarios fail against the current binding because it never sends the second Metadata request. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoVZT5Lb5aAUG57ioRa
…own broker id A raw API request stream addressed to a non-zero broker id that the route's table does not know is no longer reset at once. It is held, the route's Metadata refresh is triggered (the same metaFlush the fetch and produce clients use), and the stream is reset with the existing reset only after that refresh has completed or failed. There is no retry, so the answer to that attempt is the reset even if the refreshed table now has the id, and the caller's next request meets a fresh table. KafkaClientRoute gains the reverse of its meta flush registry: a one-shot completion callback that the meta client fires after a Metadata response has rewritten the table and when its stream fails. Streams hitting the same unknown id share one flush and are reset together; a route with no meta stream resets at once. The same holds when a reconnect finds the id gone. An unknown id gets no entry in clientsByAffinity. Fixes #3213 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoVZT5Lb5aAUG57ioRa
…cation-servers' into fix/3213-kafka-api-stale-broker-id
jfallows
changed the base branch from
develop
to
test/3212-kafka-api-broker-application-servers
November 14, 2026 21:10
This was referenced Nov 15, 2026
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
A raw API request stream carries the id of the broker to connect to as its affinity. A non-zero id that the route's broker table does not know used to be reset at once by
newStream, and nothing refreshed the table, so the caller's next request could meet the same stale table.The stream is now held while the route's Metadata refresh runs, and is reset with the same reset as before only after that refresh has completed or failed.
clientRoute.metaFlush, whichKafkaClientFetchFactoryandKafkaClientProduceFactoryalready call when a broker leaves or changes.clientsByAffinity, as before, so the map stays bounded by the broker table.onNetClosedgets nometaFlush: in fetch and produce it serves a connected broker that went away, which this issue does not cover.Design: #3213 (comment) (revised design), following the decision recorded on the issue.
New mechanism
KafkaClientRoutegains a completion registry:registerMetaRefreshed/unregisterMetaRefreshedand ametaRefreshedfan-out, the reverse ofregisterMetaFlush/metaFlush, plushasMeta(). The API factory registers a one-shot callback before it flushes.KafkaClientMetaFactoryfiresmetaRefreshedafter a Metadata response has rewritten the table, and from the meta stream'scleanupApplicationwhen it fails. The first completion or failure releases the waiting streams.No existing mechanism fits because
metaFlushis fire-and-forget. Nothing in the module reported a refresh finishing or failing:KafkaClientRouteheld only the table and the flush list, and a failure was visible only inside the meta client.Alternatives rejected:
metaFlush. This does not answer "only after the refresh".Mirrored pattern
KafkaClientFetchFactory/KafkaClientProduceFactorycallclientRoute.metaFlush.accept(traceId). The registry mirrorsKafkaClientRoute's existingArrayUtillist ofLongConsumerflushes. The waiting queue mirrorsKafkaApiClient.pending.Fixes #3213
Test evidence
Test-first: the first commit holds only the scripts and IT methods, the second the production change.
New and changed scripts, all under
specs/binding-kafka.spec:streams/network/api/create.topics.v7.broker.unknown: now plays a second Metadata exchange before the reset (the id is still absent from the refreshed table).create.topics.v7.broker.unknown.refreshed(network and application pairs): the refreshed table lists broker 9 and moves partition 1 to it. The stream is still reset and no connection is made to broker 9.create.topics.v7.broker.unknown.refresh.failed(network and application pairs): the second Metadata request is answered with an abort of the meta connection. The stream is reset.KafkaCreateTopicsITand the runtimeKafkaCreateTopicsIT.broker,broker.zero,broker.bootstrapandbroker.negotiatedscripts are untouched. They run in the same class and pass.On the first commit alone (
f62c7415a), with unchanged production code:KafkaCreateTopicsIT: 13 of 13. Spec applicationKafkaCreateTopicsIT: 6 of 6. These only pair scripts with each other.KafkaCreateTopicsIT: 3 scenarios fail,shouldRejectCreateTopicsV3ToUnknownBroker,...ToUnknownBrokerRefreshedand...ToUnknownBrokerWhenRefreshFails. Each expected the second Metadata request (read 26 ... 3s # metadata) and saw none, because the binding reset the stream without refreshing; each then times out at 5 s on the rerun. The other methods in the class pass. Messages kept ascommit1-failing-runtime-IT.login the session scratchpad.With the production commit: runtime
KafkaCreateTopicsITpasses 15 of 15.Order of the reset after the refresh was observed, not scripted. With temporary trace output (removed before the commit), each scenario printed: initial meta response, then
metaFlush fired, then (second response decoded, or meta failure), thenrefresh released waiting=1. The release came only after the refresh finished or failed.Flow control: a held stream gets no WINDOW and sends no data. It is answered with RESET on the initial side and ABORT on the reply side, the same
cleanupAppthe reconnect path already used. There is no new credit path.Verification of the head (
clean verify -pl specs/binding-kafka.spec,runtime/binding-kafka, checkstyle, license and notice checks on,-Dmaven.build.cache.skipCache=true, after installing upstream with-am -DskipTests -DskipITs -Dskip.checks=true): BUILD SUCCESS.specs/binding-kafka.spec: unit tests 226 run, 0 failures; ITs 476 run, 0 failures, 12 skipped.runtime/binding-kafka: unit tests 229 run, 0 failures; ITs 449 run, 0 failures, 67 skipped. This includes the module's jacoco coverage check.Not delivered
refresh.failedpair does not assert what the meta stream sees. Aread abortedafter a flushed meta data extension was never delivered to the client script, including for an existing meta script with an abort appended. I did not find the cause. The client script asserts only the reset of the API stream, and the runtime IT does not assert the meta stream's fate either.reconnectAttemptinKafkaClientApiFactoryis still never reset (found while reading, unrelated here).runtime/engine, the examples tests that CI runs with Docker Compose, and anything against a real multi-broker cluster.develop.broker,broker.zeroandbroker.unknownscripts and methods to the same applicationKafkaCreateTopicsIT. The.unknownapplication client is unchanged here. A rebase after test(binding-kafka): pair the broker-addressed api request application clients with servers #3215 should only conflict textually in that IT class.Generated by Claude Code