nghttpx: Listen TCP and UNIX domain sockets on worker thread#2377
nghttpx: Listen TCP and UNIX domain sockets on worker thread#2377tatsuhiro-t merged 1 commit intomasterfrom
Conversation
Previously, nghttpx listens TCP and UNIX domain sockets on a dedicated thread, and then distributes the accepted connection to the one of worker threads. With this commit, nghttpx listens those sockets on each worker thread. For TCP sockets, SO_REUSEPORT is used to load balance the connections. This removes the need for inheriting file descriptors via environment variables. For UNIX domain sockets, because there is no SO_REUSEPORT equivalent for them, they are created as before, but they are handled per worker. The support for legacy deprecated environment variables has been removed. ocsp-startup option has been deprecated due to this change. OCSP will be remove very soon.
There was a problem hiding this comment.
Pull Request Overview
This PR updates nghttpx to listen for TCP and UNIX domain socket connections directly on worker threads rather than on a dedicated listener thread. Key changes include moving socket listening logic into worker threads (with SO_REUSEPORT used for TCP) and removing legacy acceptor and environment variable support, as well as adjusting related APIs in the connection handler and accept handler.
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/shrpx_worker_process.cc | Removed dedicated-thread acceptor calls for graceful shutdown. |
| src/shrpx_worker.h | Added new listener-related methods and refactored API. |
| src/shrpx_worker.cc | Updated event loop, server socket setup, and listener control. |
| src/shrpx_connection_handler.{h,cc} | Removed legacy acceptor methods and ocsp-based acceptor enabling. |
| src/shrpx_config.cc | Logged deprecation warning for the ocsp-startup option. |
| src/shrpx_accept_handler.{h,cc} | Modified to use Worker instead of ConnectionHandler for events. |
Comments suppressed due to low confidence (1)
src/shrpx_worker.cc:691
- [nitpick] Add clarifying comments to explain the API isolation logic that differentiates socket selection based on worker index and alt_mode.
if (api_isolation) { ... }
| #endif // IPV6_V6ONLY | ||
|
|
||
| #ifdef TCP_DEFER_ACCEPT | ||
| val = 3; |
There was a problem hiding this comment.
[nitpick] Consider replacing the magic number '3' for TCP_DEFER_ACCEPT with a named constant to enhance code clarity.
| val = 3; | |
| val = TCP_DEFER_ACCEPT_TIMEOUT; |
Previously, nghttpx listens TCP and UNIX domain sockets on a dedicated thread, and then distributes the accepted connection to the one of worker threads. With this commit, nghttpx listens those sockets on each worker thread. For TCP sockets, SO_REUSEPORT is used to load balance the connections. This removes the need for inheriting file descriptors via environment variables. For UNIX domain sockets, because there is no SO_REUSEPORT equivalent for them, they are created as before, but they are handled per worker.
The support for legacy deprecated environment variables has been removed.
ocsp-startup option has been deprecated due to this change. OCSP will be remove very soon.