Skip to content

Add support for "sd_listen_fds" socket activation socket support for gRPC and HTTP listeners#589

Open
networkException wants to merge 1 commit intografana:mainfrom
networkException:network-sd_listen_fd
Open

Add support for "sd_listen_fds" socket activation socket support for gRPC and HTTP listeners#589
networkException wants to merge 1 commit intografana:mainfrom
networkException:network-sd_listen_fd

Conversation

@networkException
Copy link
Copy Markdown

@networkException networkException commented Sep 30, 2024

What this PR does:

This pull request adds support for server to be used with systemd's socket activation by expecting an open file descriptor to be announced using environment variables.

To make use of this set either HTTPListenNetwork or GRPCListenNetwork to "sd_listen_fd" and HTTPListenAddress or GRPCListenAddress either to an ASCII string passed as the FileDescriptorName= from a systemd.socket unit or "LISTEN_FD_$n", where $n is the file descriptor number, starting with 3 (SD_LISTEN_FDS_START).

By default, when using "sd_listen_fd", the address will be "LISTEN_FD_3".

This patch makes use of the coreos/go-systemd/v22/activation library (which was already included as an indirect dependency). Unfortunately their implementation doesn't allow call sites to get a view of the listeners both by file descriptor number and file descriptor name, as the highlevel helpers cannot be used.

This is similar in spirit to #511, I'll happily include unix socket support in the listen helper this change introduces as part of the rebase.

Which issue(s) this PR fixes:

Checklist

  • Tests updated
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Sep 30, 2024

CLA assistant check
All committers have signed the CLA.

@networkException networkException force-pushed the network-sd_listen_fd branch 2 times, most recently from a8486aa to e379e75 Compare September 30, 2024 21:12
@networkException networkException force-pushed the network-sd_listen_fd branch 7 times, most recently from 3a887b3 to 7a0b45a Compare October 9, 2024 20:00
This patch adds support for server to be used with systemd's
socket activation by expecting an open file descriptor to be
announced using environment variables.

To make use of this set either HTTPListenNetwork or
GRPCListenNetwork to "sd_listen_fd" and HTTPListenAddress
or GRPCListenAddress either to an ASCII string passed as
the "FileDescriptorName" from a systemd.socket unit or
"LISTEN_FD_$n", where $n is the file descriptor number.

By default, when using "sd_listen_fd", the address will
be "LISTEN_FD_3".

This patch makes use of the coreos/go-systemd/v22/activation
library (which was already included as an indirect dependency).
Unfortunately their implementation doesn't allow call sites to
get a view of the listeners both by file descriptor number and
file descriptor name, as the highlevel helpers cannot be used.

See https://www.freedesktop.org/software/systemd/man/latest/systemd.socket.html#FileDescriptorName=
@networkException networkException marked this pull request as ready for review October 9, 2024 20:06
@pracucci
Copy link
Copy Markdown
Contributor

pracucci commented Apr 7, 2026

Hi! 👋 We recently merged #947 which changed the CI configuration for unit tests. To get CI passing on this PR, please rebase on the latest main branch:

git fetch origin main
git rebase origin/main
git push --force-with-lease

Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants