Skip to content

fix(websocket_server sink): release listener and connections on shutdown - #26610

Open
U-S-jun wants to merge 2 commits into
vectordotdev:masterfrom
U-S-jun:fix/websocket-server-shutdown
Open

U-S-jun wants to merge 2 commits into
vectordotdev:masterfrom
U-S-jun:fix/websocket-server-shutdown

Conversation

@U-S-jun

@U-S-jun U-S-jun commented Oct 9, 2026

Copy link
Copy Markdown

Summary

Removing a websocket_server sink during a configuration reload leaves its listener and client tasks running. Re-adding the sink on the same address can then fail to bind and shut down Vector.

This change keeps those tasks owned by the sink:

  • Close the listener and cancel pending TLS/WebSocket handshakes.
  • Give established connections one shared five-second grace period to drain queued messages, send a Going Away (1001) close frame, and wait for the peer's close response.
  • Abort and join remaining connection tasks before normal sink shutdown completes.
  • Abort owned tasks asynchronously if the sink future is dropped.

The sink also declares its TCP resource so same-address replacement waits for the previous sink to finish. Global reload logging and exit-code behavior are unchanged.

References

Vector configuration

sources:
  http_in:
    type: http_server
    address: 127.0.0.1:18082
    decoding:
      codec: json

sinks:
  discard:
    type: blackhole
    inputs: [http_in]
  live_logs:
    type: websocket_server
    inputs: [http_in]
    address: 127.0.0.1:18081
    encoding:
      codec: json

Remove and re-add live_logs, sending SIGHUP after each configuration change.

How did you test this PR?

Validated in Linux containers using Rust 1.96.1.

make test FEATURES=sinks-blackhole,sinks-websocket_server,sources-http_server \
  SCOPE="--lib -E 'test(websocket_server)'"

make check-clippy FEATURES=sinks-blackhole,sinks-websocket_server,sources-http_server

make fmt
make check-fmt
make check-markdown
make check-changelog-fragments

All 24 targeted tests passed, including resource conflicts, same-port replacement, pending handshakes, queued-message draining, sink cancellation, and the shared shutdown deadline.

Additional process-level checks:

  • Three remove/re-add cycles each with plaintext and TLS connections, verifying socket cleanup and port reuse.
  • Going Away close frames and forced cleanup of unresponsive clients after the shared grace period.
  • Injected file-descriptor exhaustion (EMFILE), verifying that existing WebSocket clients still receive events after accepting new connections stops.

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.

Added changelog.d/26442_websocket_server_shutdown.fix.md.

AI assistance: implementation and tests developed with Codex using gpt-6 astra.
@U-S-jun
U-S-jun requested a review from a team as a code owner October 9, 2026 03:33
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T08:58:00.812836Z 173ebee New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@github-actions github-actions Bot added domain: topology Anything related to Vector's topology code domain: sinks Anything related to the Vector's sinks labels Oct 9, 2026
@U-S-jun

U-S-jun commented Oct 9, 2026

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

This branch has not been deployed

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

Labels

domain: sinks Anything related to the Vector's sinks domain: topology Anything related to Vector's topology code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

websocket_server sink leaks its listener and fatally crashes Vector on reload when the address is reused

1 participant