Skip to content

fix(systemd socket activation): fix log collection for systemd sockets#24308

Open
j-c-fuchs wants to merge 4 commits intovectordotdev:masterfrom
j-c-fuchs:fix/socket-activation
Open

fix(systemd socket activation): fix log collection for systemd sockets#24308
j-c-fuchs wants to merge 4 commits intovectordotdev:masterfrom
j-c-fuchs:fix/socket-activation

Conversation

@j-c-fuchs
Copy link
Copy Markdown

@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
Copy Markdown
Contributor

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
Copy Markdown
Author

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

@j-c-fuchs
Copy link
Copy Markdown
Author

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

@j-c-fuchs
Copy link
Copy Markdown
Author

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

Added a changelog entry.

Copy link
Copy Markdown
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

@j-c-fuchs
Copy link
Copy Markdown
Author

Hi Thomas,

thank you for your remarks. I tested it once again in all four configurations (without systemd) with a python script opening the sockets and then execv into vector, see the attached files. It works in all cases.

start-with-socket.py
test.sh
vector-tcp.yaml
vector-udp.yaml

Regarding the question whether to make it configurable: Blocking sockets are unsupported starting from tokio v1.44.0. Therefore, I think a flag to configure this is unnecessary and might have the danger of potential panics. See:

@j-c-fuchs
Copy link
Copy Markdown
Author

Hi @thomasqueirozb ,

have you any further questions? Can you follow my argumentation?

@aagor
Copy link
Copy Markdown

aagor commented Mar 4, 2026

Is there something that blocks this PR? Can we do something to move forward?

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

3 participants