feat(sources): add disconnect_mode option to TCP sources - #26091
Conversation
Adds an opt-in disconnect_mode (drain/abort) config option controlling how Vector closes TCP connections on shutdown or when max_connection_duration_secs elapses. abort sets SO_LINGER=0 to force-close immediately with a RST, which is useful for write-only clients that never read from the socket and so can't detect a graceful FIN-based shutdown. All five sources default to drain, preserving existing behavior, so this is non-breaking.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a333c06982
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| _ = &mut tripwire => break, | ||
| Some(_) = &mut connection_close_timeout => { | ||
| if close_socket(reader.get_ref().get_ref().get_ref()) { | ||
| if close_socket(reader.get_ref().get_ref().get_ref(), disconnect_mode) { |
There was a problem hiding this comment.
Apply abort mode on the force-timeout path
With disconnect_mode = abort, if shutdown_timeout_secs has already elapsed (for example it is set to 0, or the connection is stuck processing a batch until the force timeout), the tripwire branch exits without calling close_socket, so SO_LINGER=0 is never applied and clients can see the old FIN behavior instead of the configured RST. Route this branch through close_socket(..., disconnect_mode) before breaking.
Useful? React with 👍 / 👎.
| #[configurable(derived)] | ||
| #[serde(default)] | ||
| disconnect_mode: DisconnectMode, |
There was a problem hiding this comment.
Update generated docs for disconnect_mode
This adds a user-facing component configuration field, but the generated component reference files were not updated (rg disconnect_mode website/cue/reference/components/sources/generated returns no entries). The new option would be absent from the published reference and generated-docs checks should fail; please run make generate-docs and commit the generated CUE updates.
AGENTS.md reference: AGENTS.md:L114-L118
Useful? React with 👍 / 👎.
Summary
Adds a
disconnect_modeconfiguration option to TCP sources (socket, logstash, fluent, syslog, statsd) that controls how connections are closed on shutdown or whenmax_connecti on_duration_secselapses.The two modes are:
drain(the default and existing behaviour) - sends aFINand waits for the client to close.abort- setsSO_LINGER=0to force close immediately withRST.The original motivation is "write-only" clients such as Serilog.Sinks.Network that never read from the socket and ther
efore cannot detect a graceful shutdown. Additionally, the "reference implementations" for the beats (logstash) and fluent protocols also use an abort style shutdown:
All sources default to
drain, so this is opt-in with no behaviour change for existing configs.Vector configuration
How did you test this PR?
tcpdump.sources::socket:tcp_disconnect_mode_abort_on_shutdown- verifies RST is received immediately on shutdown.Is this a breaking change?
Does this PR include user facing changes?
no-changeloglabel to this PR.References
Notes
@vectordotdev/vectorto reach out to us regarding this PR.pre-pushhook, please see this template.make fmtmake check-clippy(if there are failures it's possible some of them can be fixed withmake clippy-fix)make testgit merge origin masterandgit push.Cargo.lock), pleaserun
make build-licensesto regenerate the license inventory and commit the changes (if any). More details on the dd-rust-license-tool.