Repository navigation
fix(binding-kafka): abort an api request that ends before its body is sent - #3316
Merged
Merged
Conversation
… sent A stream queued on the shared KafkaApiClient that ended without sending its request body was left in pending. When it reached the head, only the request header was written to the broker and requestInFlight stayed set, so no response ever arrived and every later request on that client waited behind it. An END before the request is complete now removes a queued stream, or recycles the connection when the stream is the in-flight head, and aborts the stream's reply. Refs #3306 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoW7sUGNbaTd4o7Mcem
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
Fixes #3306
Fixes the stall: after clients abandon their CONNECT while Kafka is slow, Zilla stops completing every later session. The 31-worker/emqtt-bench setup and the unread-data observation on Zilla's Kafka connections were not reproduced here (see Not delivered), so a rerun of the original load against a build with this fix is worth doing.
Root cause
KafkaClientApiFactory.KafkaApiStream.onAppEndonly setcloseInitial, so a stream that ended without sending its request body stayed in the sharedKafkaApiClient.pendingqueue. When it reached the head,doEncodeRequestwrote only the request header to the broker and leftrequestInFlightset, so the broker waited for the rest of the frame, no response ever came, and every later request on that client queued behind it forever.mqtt-kafka triggers it because the TCP close of a pending CONNECT reaches
MqttSessionProxy.onMqttEnd, which callsdoKafkaEndon itsKafkaFindCoordinatorStream; that stream only sends its body after the binding grants a window, which a stream queued behind a slow request has not yet received.Fix
An END before
requestBytesSentreachesrequestLengthis now handled like an abort, mirroringonAppAbort/onAppResetin the same class: a queued stream leavespendingand getscleanupApp; the in-flight head recycles the connection withcleanupNet(the only case with a half-written frame on the wire), andonNetClosedthen notifies the app throughcleanupAppActive. No flag was added. Unlike the abort path, a queued stream does not recycle the shared connection.Evidence (tests first)
create.topics.v7.request.endedin the existingKafkaCreateTopicsITclasses (application and network spec ITs, and the runtime IT), paired client/server scripts: a request ends without its body, the binding must abort it and recycle the connection, and the next request on the same client must complete.TestTimedOutException, the binding never aborts the ended stream (a traced run showedonAppEnd sent=0 head=trueand nothing further). With the fix it passes. The spec-level pairs pass.write closebeforeconnected. That path is covered only by the real-broker run below../mvnw license:format, thenverifyonspecs/binding-kafka.spec(631 tests, 0 failures) andruntime/binding-kafka(538 tests, 0 failures), with checkstyle and jacoco, run with-Dmaven.build.cache.enabled=false.Real broker, before and after
Setup:
examples/mqtt.kafka.proxy(apache/kafka:4.1.1, Zilla image built from develop,-w 4), Kafka throttled withdocker update --cpus 0.3, four processes sending MQTT 3.1.1 clean-session CONNECTs at 150/s for 30 s and closing the socket after 3 s without reading CONNACK (about 16,500 abandoned connects). Kafka then restored to 3 CPUs.On develop the broker request log showed Zilla sending only DESCRIBE_CONFIGS and METADATA, never FIND_COORDINATOR, and a live
jdbdump of the FIND_COORDINATORKafkaApiClientshowedrequestInFlight = true, 16,431 streams inpending, and a head stream withinitialClosed, zero request bytes sent and no reply, on a healthy idle connection. Disablingclient.connection.pooldid not change the stall, soKafkaClientConnectionPoolis not involved.Not delivered
onAppAbort/onAppResetstill recycle the shared connection when a queued stream aborts; this is unchanged and can fail an unrelated in-flight request.MqttKafkaSessionFactoryis untouched: after the binding aborts the reply of an ended stream,onKafkaFailurecontinues setup for a session whose client is gone. Kept out to avoid the mqtt-kafka: some of the first clients after start-up are disconnected right after CONNACK, with nothing logged #3308 and mqtt-kafka: a QoS 2 PUBLISH crashes the engine (NoSuchElementException in KafkaOffsetCommitStream.onKafkaWindow) #3303 overlap.🤖 Generated with Claude Code
https://claude.ai/code/session_01SiHVoW7sUGNbaTd4o7Mcem