out_forward: drop keepalive sockets with failed or mismatched acks#5436
Open
JSap0914 wants to merge 1 commit into
Open
out_forward: drop keepalive sockets with failed or mismatched acks#5436JSap0914 wants to merge 1 commit into
JSap0914 wants to merge 1 commit into
Conversation
When a chunk's ack times out or comes back with a chunk id that does not match the one tracked for its socket, the keepalive connection may still carry an in-flight/stale ack for a previous chunk. Returning that socket to the reuse pool lets the stale ack be read against a chunk sent on the reused socket, permanently offsetting every subsequent ack and flooding the log with "ack in response and chunk id in sent data are different" warnings until the forwarder is restarted (reported with keepalive + flush_thread_count > 1). Add ConnectionManager#discard, which revokes a keepalive socket (or closes a non-keepalive one) instead of checking it back in, and use it from ack_check on the FAILED and CHUNKID_UNMATCHED paths so the tainted connection is torn down and the next chunk uses a fresh connection with a clean ack stream. Successful acks still reuse the socket as before. Fixes fluent#4057 Signed-off-by: JSup <hanjisang0914@gmail.com>
Watson1978
reviewed
Jul 16, 2026
Comment on lines
+94
to
+95
| sock.close_write rescue nil | ||
| sock.close rescue nil |
Contributor
There was a problem hiding this comment.
[nits] These line now appears in
fluentd/lib/fluent/plugin/out_forward/connection_manager.rb
Lines 76 to 77 in e833442
When you add a tiny private method (like a close_socket), it would remove duplicates.
Watson1978
approved these changes
Jul 16, 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.
Which issue(s) this PR fixes:
Fixes #4057
What this PR does / why we need it:
In Forwarder-Aggregator mode with
keepalive trueandflush_thread_count> 1, when the aggregator restarts/reconnects the forwarder starts loggingendlessly, and never recovers on its own until the pod is killed.
Root cause: when a chunk's ack times out (
FAILED) or comes back with a chunk id that does not match the one tracked for its socket (CHUNKID_UNMATCHED),ack_checkreturned the keepalive socket to the reuse pool viaConnectionManager#close(→SocketCache#checkin). Such a connection may still carry an in-flight/stale ack for a previous chunk. When the socket is checked out again for a new chunk, that stale ack is read first and compared against the new chunk's id, so it never matches. From then on every ack on that connection is offset by one chunk, producing an unbounded stream of mismatch warnings.This PR adds
ConnectionManager#discard, which revokes a keepalive socket (or closes a non-keepalive one) instead of checking it back in, and uses it fromack_checkon theFAILEDandCHUNKID_UNMATCHEDpaths. The tainted connection is torn down, so the next chunk uses a fresh connection with a clean ack stream and the warning storm stops. Successful acks keep reusing the socket exactly as before.Docs Changes:
None.
Release Note:
out_forward: stop the endless "ack in response and chunk id in sent data are different" warning storm by discarding (instead of reusing) a keepalive socket whose ack failed or came back with a mismatched chunk id.
Tests (
ruby 3.4.10):test/plugin/out_forward/test_connection_manager.rb— new#discardcases: closes a non-keepalive socket, revokes a keepalive socket instead of checking it in, and confirms a discarded keepalive socket is not reused (a checked-in one is).test/plugin/test_out_forward.rb— newack_checkcases: the socket is discarded onCHUNKID_UNMATCHEDandFAILED, and reused onSUCCESS.The new tests fail on
master(the mismatched/failed ack socket is reused) and pass with this change.