Skip to content

feat(sources): add disconnect_mode option to TCP sources - #26091

Open
tronboto wants to merge 1 commit into
vectordotdev:masterfrom
tronboto:disconnect-mode-2
Open

feat(sources): add disconnect_mode option to TCP sources#26091
tronboto wants to merge 1 commit into
vectordotdev:masterfrom
tronboto:disconnect-mode-2

Conversation

@tronboto

Copy link
Copy Markdown
Contributor

Summary

Adds a disconnect_mode configuration option to TCP sources (socket, logstash, fluent, syslog, statsd) that controls how connections are closed on shutdown or when max_connecti on_duration_secs elapses.

The two modes are:

  • drain (the default and existing behaviour) - sends a FIN and waits for the client to close.
  • abort - sets SO_LINGER=0 to force close immediately with RST.

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

sources:
  tcp_in:
    type: socket
    mode: tcp
    address: "0.0.0.0:9000"
    shutdown_timeout_secs: 5
    disconnect_mode: abort  # omit for default drain behaviour
sinks:
  out:
    type: console
    inputs: [tcp_in]
    encoding:
      codec: text

How did you test this PR?

  • Manual testing with netcat and a write-only Python client against both modes, verifying FIN and RST behaviour using tcpdump.
  • A new unit test added to sources::socket:
    • tcp_disconnect_mode_abort_on_shutdown - verifies RST is received immediately on shutdown.

Is this a breaking change?

  • Yes
  • No

Does this PR include user facing changes?

  • Yes. Please add a changelog fragment based on our guidelines.
  • No. A maintainer will apply the no-changelog label to this PR.

References

Notes

  • Please read our Vector contributor resources.
  • Do not hesitate to use @vectordotdev/vector to reach out to us regarding this PR.
  • Some CI checks run only after we manually approve them.
    • We recommend adding a pre-push hook, please see this template.
    • Alternatively, we recommend running the following locally before pushing to the remote branch:
      • make fmt
      • make check-clippy (if there are failures it's possible some of them can be fixed with make clippy-fix)
      • make test
  • After a review is requested, please avoid force pushes to help us review incrementally.
    • Feel free to push as many commits as you want. They will be squashed into one before merging.
    • For example, you can run git merge origin master and git push.
  • If this PR introduces changes Vector dependencies (modifies Cargo.lock), please
    run make build-licenses to regenerate the license inventory and commit the changes (if any). More details on the dd-rust-license-tool.

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.
@tronboto
tronboto requested a review from a team as a code owner August 12, 2026 19:20
@github-actions github-actions Bot added the domain: sources Anything related to the Vector's sources label Aug 12, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment on lines 337 to +339
_ = &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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Comment thread src/sources/socket/tcp.rs
Comment on lines +82 to +84
#[configurable(derived)]
#[serde(default)]
disconnect_mode: DisconnectMode,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: sources Anything related to the Vector's sources

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant