Repository navigation
out_forward: stop a send after send_timeout when the server does not read - #5682
Merged
kenhys merged 4 commits intoDec 1, 2026
Merged
Conversation
…read send_timeout was only passed to SO_SNDTIMEO, which does not end IO#write or IO.copy_stream. A send to a server that stopped reading blocked the flush thread. * Send with write_nonblock and raise SendTimeoutError when the send makes no progress for send_timeout. 0 still means no timeout * Do not wait for an ACK or for SO_LINGER on a timed out socket. Reset it without keepalive, and close it normally with keepalive, because it may still hold earlier chunks * Drop unread data before a failed keepalive socket is closed, so that close does not reset the connection * Close a TCP socket after shutdown(:WR), not after close_write. Ruby keeps the GVL while such a close waits for SO_LINGER, and Windows cannot close a non-blocking socket with SO_LINGER and unsent data * Set no SO_LINGER for send_timeout 0, and 1 second for a value below 1 second. SO_LINGER of 0 seconds resets the connection on close Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
Watson1978
force-pushed
the
out-forward-send-timeout-bounds-write
branch
from
November 26, 2026 01:58
152a03f to
b65ed09
Compare
Watson1978
marked this pull request as ready for review
November 26, 2026 01:59
kenhys
requested changes
Nov 26, 2026
* Run the tests for a server that does not read, and for send_timeout 0, with TLS too * Cover the wait for a readable socket, which a TLS write can ask for Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
kenhys
reviewed
Nov 30, 2026
…esponse A timed out send skipped the ack check, so its node stayed available, unlike after other failed sends. Disable the node at once. Waiting for the ack check would do it only after ack_response_timeout, because the server keeps the connection open without reading. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
… comment Waiting for the ACK of a timed out send can block the ACK thread with TLS 1.3 when the server starts reading late. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
kenhys
approved these changes
Dec 1, 2026
kenhys
pushed a commit
to Watson1978/fluentd-docs-gitbook
that referenced
this pull request
Dec 1, 2026
send_timeout is a limit on the time without progress, not on the whole send. fluent/fluentd#5682 makes it stop a send, so describe what it limits and what changes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
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 #5680
What this PR does / why we need it:
send_timeoutwas only passed toSO_SNDTIMEO, which does not end a write of Ruby, so a send to a server that stopped reading blocked the flush thread until the server read again or closed the connection. The send now useswrite_nonblockand fails withSendTimeoutErrorwhen it makes no progress forsend_timeout. It is not a limit on the whole send, and a server that reads very slowly can also fail.send_timeout 0still means no timeout.IO.copy_streamis replaced by a read and write loop, so the file buffer with plain TCP no longer usessendfile. Sending a 512 MiB chunk to in_forward on the same host took about 10% longer on my machine (0.47s to 0.52s). The memory buffer was not slower.SO_LINGER(=send_timeout) stays on the transfer socket, soclosestill waits until the server has the data, as before. Two things around it change. A plain TCP socket is now closed aftershutdown(:WR)and not afterclose_write, also in the keepalive cache. Ruby keeps the GVL while it closes a socket afterclose_write, so that wait could stop every other thread, and with the new write loop it did so on every send to a receiver in the same process. Windows also needs the shutdown to close a non-blocking socket that hasSO_LINGERand unsent data. And asend_timeoutof 0 or below 1 second setSO_LINGERto 0 seconds (not on Windows), which resets the connection oncloseand can drop data. Now 0 sets noSO_LINGER, and a value below 1 second sets 1 second.A timed out socket does not wait for an ACK or for
SO_LINGER. Without keepalive it is reset, because it only holds the chunk that is sent again. Withrequire_ack_response, its node is also disabled at once, as after other failed sends. A keepalive socket is closed normally by the purge timer, after its unread data is dropped, because it may still hold earlier chunks. Its unsent data then stays in the kernel until the server reads or TCP gives up. Withoutrequire_ack_response, an earlier chunk on it can still be lost with TLS 1.3, when data from the server arrives after the close. That can already happen without keepalive.Docs Changes:
fluent/fluentd-docs-gitbook#731
Release Note:
out_forward: stop a send after send_timeout when the server does not read.
send_timeouthad no effect on a send before, so a small value can now fail sends to a slow server.🤖 Generated with Claude Code