Repository navigation
fix(binding-kafka): recover produce and fetch when a broker connection is lost - #2621
Merged
Merged
Conversation
When a produce or fetch connection to a broker ends, aborts or resets, the client streams cleaned up without refreshing metadata. Cached partition leaders kept pointing at the departed broker until the next scheduled metadata refresh, so reconnects targeted the same broker. Trigger an immediate metadata refresh from the network end, abort and reset handlers of the client produce and fetch streams, reusing the existing metaFlush hook used for retriable error codes. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 4c5034c)
When a produce connection to a broker aborted or reset, the client produce stream reset the application stream without an error code. The cache treated this as a non-retriable unknown error and failed the pending records, instead of reconnecting and resending them as it does for other retriable errors. Report NETWORK_EXCEPTION on network abort or reset in the client produce stream, and handle it in the cache server produce fanout the same way as NOT_LEADER_FOR_PARTITION, so the cache client reconnects and resends the pending records. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 350522a)
…ode buffer The produce client credits the application window per record as value size plus a fixed framing padding, but a record's key and headers are encoded into the same buffer slot. When key and headers exceed the padding and records accumulate while a produce request is in flight, the encoded records overrun the encode slot. - raise the advertised window padding once a record's framing (batch, record header, key and headers) exceeds the configured framing size - size the pre-encode capacity check from the current record instead of the previous record's value size - reset the stream rather than write past the encode slot when a record cannot fit Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 83f8ac1)
…ivery The cache server acknowledged every entry up to the latest offset signaled by the cache client whenever the produce client stream was fully acknowledged, including entries not yet sent or still in flight. If the in-flight produce request then failed with a retriable error, those entries were already marked complete, so they were skipped on reconnect and never produced, while the producer had already been told they succeeded. Acknowledge success only up to the last entry delivered by the cursor, and defer the acknowledgement when skipping a completed entry until all in-flight data has been acknowledged. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 83c24bb)
Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 2d84d28)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BHiEhWWo5S4veNzeZBcndj
…vered and acknowledged The cache server flushed a success acknowledgement to its members with the offset last signaled by the cache client. When the broker acknowledged a batch while later entries were delivered but still in flight, or appended but not yet delivered, those entries were also marked complete. If the in-flight request then failed with a retriable error, they were skipped on reconnect and never produced, while the producer had already been told they succeeded. Withhold the success flush while delivered data is unacknowledged and clamp the flushed offset to the last entry delivered by the cursor. This supersedes the deferral at the dirty entry skip, which is restored to an unconditional flush. Add a spec where the broker acknowledges the first record while the second is in flight and the connection then fails, asserting the second record is resent after reconnect. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BHiEhWWo5S4veNzeZBcndj
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
Ports #2616 from
support/1.xtodevelop(5 commits cherry-picked with-x), plus two follow-up commits needed because develop's produce acknowledgement path differs from 1.x.When a produce or fetch connection to a broker ended, aborted or reset, the client did not recover:
NETWORK_EXCEPTIONon network abort or reset, and the cache server produce fanout handles it likeNOT_LEADER_FOR_PARTITION, reconnecting and resending pending records.Differences from the
support/1.xchangeKafkaClientProduceFactory: kept develop'sguardconstructor argument alongside the newinitialPad/initialPadMininitialisation.KafkaCacheServerProduceFactoryack path: develop flushes a success ack to cache client members from the broker's produce flush, carrying the offset last signaled by the cache client. The 1.x change (deferring the ack at the dirty-entry skip and clamping the flushed offset) does not apply as written. New specpartition.not.leader.reconnect.in.flight.acknowledgedreproduces the bug on develop: the broker acknowledges the first record while the second is in flight, the connection then fails, and the second record is never resent. The last commit fixes this by withholding the success flush while delivered data is unacknowledged and clamping the flushed offset to the last delivered entry. The dirty-entry skip is left as the original unconditional flush.ClientProduceIT: the ported tests useclient.yaml, sinceclient.when.topic.yamldoes not exist on develop.Testing
./mvnw verifyonruntime/binding-kafkawithCacheProduceIT,ClientProduceIT,CacheMergedIT,ClientMergedIT,CacheFetchIT,ClientFetchIT: 299 run, 0 failures.specs/binding-kafka.specProduceIT: 0 failures. The newCacheProduceIT.shouldReconnectPartitionNotLeaderInFlightAcknowledgedfails on develop without the last commit and passes with it. The full./mvnw installand the remainingbinding-kafkaITs have not been run.🤖 Generated with Claude Code
https://claude.ai/code/session_01BHiEhWWo5S4veNzeZBcndj