Skip to content

feat(node-server): implement socket activation - #3351

Closed
septatrix wants to merge 2 commits into
nitrojs:v3from
septatrix:feat/systemd-socket-activation
Closed

feat(node-server): implement socket activation#3351
septatrix wants to merge 2 commits into
nitrojs:v3from
septatrix:feat/systemd-socket-activation

Conversation

@septatrix

Copy link
Copy Markdown
Contributor

🔗 Linked issue

This expands upon #1129.

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

This implements the LISTEN_FDs socket activation protocol to allow starting the server by passing a preconfigured socket file descriptor. This is useful to allow an unprivileged process to bind to privileged ports or addresses outside the namespace.

Testing can be done using the following commands:

# Bind to single port
systemd-socket-activate -l 8000 node playground/.output/server/index.mjs
# Bind to unix socket (this triggers the `addressInfo === null` codepath)
systemd-socket-activate -l ./socketname node playground/.output/server/index.mjs
# Bind to multiple ports, only first passed FD will be used (see code)
systemd-socket-activate -l 8000 -l 9000 node playground/.output/server/index.mjs

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@septatrix
septatrix requested a review from pi0 as a code owner May 6, 2025 15:33
This implements the LISTEN_FDs socket activation protocol to allow
starting the server by passing a preconfigured socket file descriptor.
This is useful to allow an unprivileged process
to bind to privileged ports or addresses outside the namespace.
@septatrix
septatrix force-pushed the feat/systemd-socket-activation branch from 9044fb5 to 6f11209 Compare May 6, 2025 23:14
@pi0

pi0 commented May 7, 2025

Copy link
Copy Markdown
Member

Thanks for PR ❤️ Since Nitro v3 will be based on srvx can you please raise an issue there to first discuss the API design? 🙏🏼 (we need to consider supporting Node, Deno and Bun and perhaps using an approach to use a srvx plugin to be opt-in)

(closing PR mainly for triage)

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.

2 participants