TCP Socket Listen: Accept Queue [ESTABLISHED CONNECTIONS] - #17
Open
Abishekcs wants to merge 5 commits into
Open
Conversation
Query the kernel's TCP accept-queue depth (accepted-but-unconsumed connections) for a listening socket identified by port number, instead of a facil.io uuid. Uses Linux's netlink/inet_diag (NETLINK_INET_DIAG) interface to dump TCP_LISTEN sockets and match by bound port, summing across matches to handle dual-stack (IPv4/IPv6) and SO_REUSEPORT listeners on the same port. Linux-only; compiled out on other platforms since netlink has no equivalent there.
Abishekcs
force-pushed
the
TCP/kernel-accept-queue
branch
from
August 15, 2026 18:20
245a59d to
16666c2
Compare
…y port Adds fio_accept_queue_backlog_port(port), which asks the kernel directly how many already-connected clients are sitting in a listening socket's accept queue, waiting for the app to pick them up looked up by port number instead of a facil.io connection handle. This means you can check it without already having a live uuid for that socket. Also renames the existing uuid-based function from fio_accept_queue_depth to fio_accept_queue_backlog, to match the kernel's own term for this value (the accept backlog). On the Ruby side, adds Iodine.accept_queue_backlog(port), which returns the queue length as an integer, or nil if nothing is listening on that port (or if this isn't running on Linux the underlying kernel query only exists there).
…y port On Linux, adds fio_accept_queue_backlog_port(port), which asks the kernel directly how many already-connected clients are sitting in a listening socket's accept queue, waiting for the app to pick them up looked up by port number rather than needing an existing facil.io connection handle. This works by opening a netlink socket and asking the kernel's socket-diagnostics interface (the same one `ss`/`netstat` use) to list all TCP sockets currently in the LISTEN state, for both IPv4 and IPv6, then matching by port. If more than one listening socket is bound to that port (dual-stack, or multiple worker processes sharing a port), their queue counts are added together. Returns -1 if nothing is listening on the port, or if the query fails. Not available on non-Linux platforms, since this relies on a Linux-only kernel interface (netlink).
Covers the main behaviors: nil when nothing is listening on the port, 0 for a listener with no pending connections, a positive count once clients connect but before the app accepts them, the count tracking exactly as more clients connect, and it dropping back to 0 once the app accepts everything. Also checks input handling: a numeric string port works the same as an Integer, and invalid ports (0, negative, above 65535) raise the expected errors. Linux only, since the underlying kernel query (netlink) doesn't exist elsewhere the whole spec is skipped on other platforms.
Abishekcs
marked this pull request as ready for review
August 17, 2026 10:24
Abishekcs
marked this pull request as draft
August 17, 2026 10:27
Abishekcs
marked this pull request as ready for review
August 17, 2026 10:38
Member
Author
|
@rsamoilov PR is ready for review. Please review it whenever you are free. Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue (Rage): rage-rb/rage#379
What this PR does ?
Adds a way to check how many connections are currently waiting in a listening socket's accept queue, by port number, on Linux.
When a client connects, the kernel completes the TCP handshake before the app gets involved, and the holds the finished connection in the accept queue until the app calls
accept(). This queue has a fixed max size, the backlog, bounded by somaxconn, and if it fills up, new connections get dropped from the SYN Queue or reset before the app ever sees them. Checking its depth is a useful health signal, if it stays near the limit, the app isn't accepting fast enough.fio_accept_queue_backlog_port(port)queries the kernel directly, matching by port instead of requiring a facil.io connection handle. It checks both IPv4 and IPv6m and sums the depths if more than one listening socket shares the port. A Ruby binding, Iodine.accept_quque_backlog(port), is included.Refrences
Testing
test.mp4