Skip to content

Add Unix domain socket support#36

Closed
jjn1056 wants to merge 4 commits intomainfrom
feat/unix-socket
Closed

Add Unix domain socket support#36
jjn1056 wants to merge 4 commits intomainfrom
feat/unix-socket

Conversation

@jjn1056
Copy link
Copy Markdown
Owner

@jjn1056 jjn1056 commented Feb 10, 2026

Summary

  • Add socket => $path option to PAGI::Server for listening on Unix domain sockets instead of TCP, enabling nginx reverse proxy (proxy_pass http://unix:/tmp/pagi.sock) and benchmark (TechEmpower) setups
  • Works with both single-worker and multi-worker modes; socket file auto-cleaned on shutdown, stale sockets removed on startup
  • Add --socket PATH CLI option to pagi-server, with full POD documentation including an experimental feature section
  • Add socket_mode => $octal option to set file permissions on the socket after creation (e.g., 0660), useful when the reverse proxy runs as a different user; includes --socket-mode MODE CLI flag

Closes #26. Supersedes #31 (re-implemented cleanly on current main).

Test plan

  • prove -l t/43-unix-socket.t — 12 subtests covering option parsing, mutual exclusivity validation, single-worker request/response, multi-worker request/response, socket cleanup, stale socket removal, socket_mode permissions (0660, 0666), default permissions, multi-worker with socket_mode, and socket_mode without socket
  • prove -l t/ — full test suite passes (no regressions)
  • Manual: pagi-server --socket /tmp/pagi.sock --socket-mode 0660 ./examples/01-hello-http/app.pl + curl --unix-socket /tmp/pagi.sock http://localhost/

🤖 Generated with Claude Code

jjn1056 and others added 4 commits February 10, 2026 17:38
Enables listening on Unix domain sockets via `socket => $path` option,
supporting nginx reverse proxy (`proxy_pass http://unix:/tmp/pagi.sock`)
and benchmark scenarios (TechEmpower).

- Parse `socket` option in _init, validate mutual exclusivity with host/port
- Listen on Unix socket in _listen_singleworker via IO::Async addr family
- Clean up socket file on shutdown, remove stale sockets on startup
- Add socket_path accessor

Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Create Unix listen socket in parent, workers inherit it via fork
- Reuseport is N/A for Unix sockets (workers share parent socket)
- Clean up socket file in _initiate_multiworker_shutdown
- Guard reuseport and bound_port logic for socket mode
- Pass socket config to worker server instances

Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Add --socket to Runner._parse_server_options, suppress host/port when set
- Document socket option in Server.pm configuration section
- Add UNIX DOMAIN SOCKET SUPPORT (EXPERIMENTAL) POD section
- Document socket_path accessor
- Add --socket to bin/pagi-server POD

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Allow setting file permissions on Unix domain sockets via the
socket_mode constructor option (numeric, e.g., 0660) or --socket-mode
CLI flag (octal string). chmod is applied after socket creation in
both single-worker and multi-worker modes. Silently ignored when
socket is not set.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
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.

Unix socket listening instead of TCP?

1 participant