Skip to content

Conversation

benjamin-awd
Copy link
Contributor

@benjamin-awd benjamin-awd commented Aug 22, 2025

Summary

This PR enables the NATS source to drain messages when shutting down. Currently we unsubscribe, which is not as robust as draining before disconnect since inflight messages can be dropped.

Closing a connection (using close()), or unsubscribing from a subscription, are generally considered immediate requests. When you close or unsubscribe the library will halt messages in any pending queue or cache for subscribers. When you drain a subscription or connection, it will process any inflight and cached/pending messages before closing.

More details here: https://docs.nats.io/using-nats/developer/receiving/drain

How did you test this PR?

Ran this on a relatively high velocity NATS subject (messages redacted, but timestamp is the native timestamp created by Vector) with a console sink to stdout.

With this change, events are still handled even after the shutdown is triggered.

{"timestamp":"2025-08-22T11:00:58.831517Z", "payload: foo"}
{"timestamp":"2025-08-22T11:00:58.834378Z", "payload: bar"}
^C
2025-08-22T11:00:58.860597Z  INFO vector::signal: Signal received. signal="SIGINT"
2025-08-22T11:00:58.860687Z  INFO vector: Vector has stopped.
2025-08-22T11:00:58.860808Z  INFO source{component_kind="source" component_id=private component_type=nats}: vector::sources::nats::source: Shutdown signal received. Draining NATS subscription...
2025-08-22T11:00:58.862056Z  INFO vector::topology::running: Shutting down... Waiting on running components. remaining_components="print, process_message, private, nats-private-v1" time_remaining="59 seconds left"
2025-08-22T11:00:58.876921Z  INFO source{component_kind="source" component_id=private component_type=nats}: vector::sources::nats::source: NATS source drained and shut down gracefully.
2025-08-22T11:00:58.877080Z  INFO async_nats: event: closed
{"timestamp":"2025-08-22T11:00:58.876851Z", "payload: baz"}
2025-08-22T11:00:58.877768Z  INFO async_nats: event: closed

Change Type

  • Bug fix
  • New feature
  • Non-functional (chore, refactoring, docs)
  • Performance

Is this a breaking change?

  • Yes
  • No

Does this PR include user facing changes?

Not sure about this one, I guess technically it's user-facing?

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

References

@benjamin-awd benjamin-awd requested a review from a team as a code owner August 22, 2025 15:27
@github-actions github-actions bot added the domain: sources Anything related to the Vector's sources label Aug 22, 2025
@pront pront enabled auto-merge August 25, 2025 16:43
auto-merge was automatically disabled August 26, 2025 15:11

Head branch was pushed to by a user without write access

@pront pront enabled auto-merge August 26, 2025 15:56
@pront pront added this pull request to the merge queue Aug 26, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 26, 2025
@pront
Copy link
Member

pront commented Aug 26, 2025

Nats integration tests failed: https://github.com/vectordotdev/vector/actions/runs/17244108073/job/48929272324

@benjamin-awd
Copy link
Contributor Author

I think the new test had some kind of race condition, made a small tweak which will hopefully deal with that

@pront pront enabled auto-merge August 27, 2025 14:50
@pront pront added this pull request to the merge queue Aug 27, 2025
Merged via the queue into vectordotdev:master with commit 84dd39a Aug 27, 2025
54 checks passed
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.

2 participants