Skip to content

fix(binding-kafka): recover produce and fetch when a broker connection is lost - #2621

Merged
jfallows merged 7 commits into
developfrom
claude/zilla-pr-2616-develop-hlesjb
Sep 30, 2026
Merged

jfallows merged 7 commits into
developfrom
claude/zilla-pr-2616-develop-hlesjb

Conversation

@jfallows

@jfallows jfallows commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

Ports #2616 from support/1.x to develop (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:

  • Metadata refresh: client produce and fetch streams now trigger an immediate metadata refresh on network end, abort and reset, so cached partition leaders stop pointing at the departed broker.
  • Produce retry: client produce reports NETWORK_EXCEPTION on network abort or reset, and the cache server produce fanout handles it like NOT_LEADER_FOR_PARTITION, reconnecting and resending pending records.
  • Encode buffer: the produce client accounts for record key and headers when advertising window padding and checking encode capacity, and resets the stream instead of writing past the encode slot.
  • Ack after delivery: the cache server no longer acknowledges entries that are not yet delivered, or delivered but still in flight, so an in-flight request failing with a retriable error doesn't lose entries.
  • Leader reset: the produce leader is reset for any known reconnect error.

Differences from the support/1.x change

  • KafkaClientProduceFactory: kept develop's guard constructor argument alongside the new initialPad / initialPadMin initialisation.
  • KafkaCacheServerProduceFactory ack 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 spec partition.not.leader.reconnect.in.flight.acknowledged reproduces 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 use client.yaml, since client.when.topic.yaml does not exist on develop.

Testing

./mvnw verify on runtime/binding-kafka with CacheProduceIT, ClientProduceIT, CacheMergedIT, ClientMergedIT, CacheFetchIT, ClientFetchIT: 299 run, 0 failures. specs/binding-kafka.spec ProduceIT: 0 failures. The new CacheProduceIT.shouldReconnectPartitionNotLeaderInFlightAcknowledged fails on develop without the last commit and passes with it. The full ./mvnw install and the remaining binding-kafka ITs have not been run.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BHiEhWWo5S4veNzeZBcndj

ankitk-me and others added 7 commits September 29, 2026 15:34
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)
…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

@jfallows jfallows left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jfallows
jfallows merged commit 502faff into develop Sep 30, 2026
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants