Repository navigation
Add socket activation support - #1516
Conversation
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
2718b23 to
cc1ce4c
Compare
cc1ce4c to
d28a45b
Compare
|
OK yay the CI error was spurious, and this is passing now. |
|
Tick the box to add this pull request to the merge queue (same as
|
d28a45b to
18a8567
Compare
|
This pull request is merged. |
18a8567 to
eab0553
Compare
Socket activation is generally nice to have / considered good practice, but this will especially be useful later because it makes parallel local (i.e. via `cabal`, not just inside a Nix build) integration testing easier. We try socket activation by default, falling back to binding a port ourselves. `--socket-activation-only` and `--no-socket-activation` force either side; `--ip`/`--port` imply the latter, since asking for an address to listen on is a request to bind it ourselves. (Use `--base-uri` if you only meant to change the advertised URI.) We use the `systemd` package's `getActivatedSockets` to pick up the inherited socket. It also takes care of a key detail: calling `setNonBlockIfNeeded` on the inherited fd so that GHC's IO manager (epoll) can handle `accept`/`recv` correctly in the threaded runtime. Without this, the server starts but connections hang — discovered via the NixOS VM integration test. The socket is acquired in `runAction` before the server state is loaded, so socket activation problems are reported promptly, and the temp server and real server share the one socket. Assisted-by: Claude Code (claude-opus-5-5)
eab0553 to
2910495
Compare
| -- Get the socket now, rather than when we start serving, so that | ||
| -- problems (e.g. a bad socket activation environment) are reported | ||
| -- before we spend a long time loading the server state. This also means | ||
| -- the temp server and the real server share the one socket. | ||
| listenSocket <- Server.acquireListenSocket listenOn | ||
| let config' = config { confListenOn = ListenOnInfallible (ExplicitSocket listenSocket) } |
|
(If the socket-opening is now early enough, I think this is ready!) |
|
Thanks for adding the commit, it makes sense to me! |
| pkgs.testers.runNixOSTest { | ||
| name = "hackage-server"; | ||
|
|
||
| containers.machine = { pkgs, ... }: { |
There was a problem hiding this comment.
Did containers not work for you? I do like it because it is much faster.
There was a problem hiding this comment.
I run on Debian and nodes seems more comprehensive since it should include more of the kernel/systemd interactions
There was a problem hiding this comment.
Note that with containers it is still running a systemd inside the container. This is standard for https://www.freedesktop.org/software/systemd/man/latest/systemd-nspawn.html, which "NixOS containers" are just a thin wrapper around.
Since there is no VM it will use the host kernel but
Socket activation is generally nice to have / considered good practice, but this will especially be useful later because it makes parallel local (i.e. via
cabal, not just inside a Nix build) integration testing easier.We try socket activation by default, falling back to binding a port ourselves.
--socket-activation-onlyand--no-socket-activationforce either side;--ip/--portimply the latter, since asking for an address to listen on is a request to bind it ourselves. (Use--base-uriif you only meant to change the advertised URI.)A key implementation detail:
setNonBlockIfNeededmust be called on the inherited fd so that GHC's IO manager (epoll) can handleaccept/recvcorrectly in the threaded runtime. Without this, the server starts but connections hang — discovered and fixed via the NixOS VM integration test.