Skip to content

Conversation

@j-c-fuchs
Copy link

@j-c-fuchs j-c-fuchs commented Nov 26, 2025

Summary

Systemd sockets are passed in blocking mode, but tokio expects them to be in non-blocking mode, see https://docs.rs/tokio/latest/tokio/net/struct.TcpListener.html#notes.
Therefore, always set sockets from systemd to non-blocking.

Vector configuration

# vector.yaml
sources:
  systemd_syslog_socket_activation:
    type: syslog
    #address: 127.0.0.1:12345
    address: systemd#1
    mode: udp
    decoding:
      codec: "json"

sinks:
  stdout:
    type: console
    inputs:
      - systemd_syslog_socket_activation
    encoding:
      codec: "json"
      json:
        pretty: true

How did you test this PR?

Start vector with systemd socket activation (udp socket, but tcp socket is the same), send logs and stop vector, see #24300 for more details.

#!/usr/bin/bash

send_logs() {
  sleep 5
  echo '{"hello": "world"}' | socat STDIN UDP:127.0.0.1:12345
  sleep 3
  echo '{"hello": "world again"}' | socat STDIN UDP:127.0.0.1:12345
  sleep 5
  pkill vector
  sleep 5
  echo '{"hello": "send after terminate"}' | socat STDIN UDP:127.0.0.1:12345
}

send_logs &
systemd-socket-activate \
  --datagram --listen 127.0.0.1:12345 \
  -E RUST_BACKTRACE=full \
  -E VECTOR_INTERNAL_LOG_RATE_LIMIT=0 \
  ./target/debug/vector -vvv \
  --config vector.yaml

Note: Unfortunately, I don't know how to add tests for this case. Unit tests seem impossible, because opening a socket and then using the corresponding file descriptor for listening violates io_safety. For integration tests, I don't know how to pass the file descriptor to the tests.

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?

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

References

See issue vectordotdev#24300.

Systemd sockets are passed in blocking mode, but tokio expects them to be
in non-blocking mode, see https://docs.rs/tokio/latest/tokio/net/struct.TcpListener.html#notes.
@j-c-fuchs j-c-fuchs requested a review from a team as a code owner November 26, 2025 23:02
@github-actions github-actions bot added the domain: sources Anything related to the Vector's sources label Nov 26, 2025
@github-actions
Copy link

github-actions bot commented Nov 26, 2025

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

@j-c-fuchs
Copy link
Author

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

@j-c-fuchs
Copy link
Author

Please, let me know if I should make a changelog entry for this fix.

@j-c-fuchs
Copy link
Author

Please, let me know if I should make a changelog entry for this fix.

Added a changelog entry.

Copy link
Contributor

@thomasqueirozb thomasqueirozb left a comment

Choose a reason for hiding this comment

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

Hi, thanks for your contribution. While this may fix systemd sockets I worry it may break other system sockets that are configured differently. Have you tested this with all possible SystemFd sockets?

  1. TCP blocking socket
  2. TCP non-blocking socket
  3. UDP blocking socket
  4. UDP non-blocking socket

Maybe we could have this behavior be configured by a flag

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.

socket source: passed UDP file descriptor not processed until shutdown

2 participants