Repository navigation
Conversation
`SocketDigest` keeps the socket's fd, but only uses it internally, for example in `socket_cookie()` and `tcp_info()`. On an HTTP/1.x session the fd is reachable through `Session::stream()`, but for HTTP/2 sessions `stream()` returns `None` and the digest is the only handle to the downstream connection. Applications that need a socket option that Pingora does not wrap have no way to get the fd there. Add `SocketDigest::raw_fd()` on unix, next to `socket_cookie()`. The fd stays owned by the connection; the doc comment says callers must not close it or do I/O on it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What
Adds
SocketDigest::raw_fd()on unix, next to the existingsocket_cookie():It returns the fd that the digest already stores and uses internally (
socket_cookie(),tcp_info(),get_recv_buf(), ...). The fd stays owned by the connection; the doc comment says that callers may read or set socket options on it but must not close it or do I/O on it.Why
On an HTTP/1.x session the downstream fd is reachable through
Session::stream(). For HTTP/2 sessionsstream()returnsNone, and the session'sDigestis the only handle to the downstream connection. An application that needs a socket option Pingora does not wrap has no direct way to get the fd there.We are building a proxy on top of Pingora and needed this to abort a downstream connection with a TCP RST (
SO_LINGERwith a zero timeout). On 0.9.1 the only way we found was to takesocket_cookie()and scan/proc/self/fd, comparing each socket'sSO_COOKIE, which is Linux-only and scans every fd of the process. With this accessor the lookup is not needed.This is a small, additive change, so I did not open a separate issue first; happy to open one if you prefer. #571 describes a related need (closing a TCP connection from the application, currently done by collecting the fd).
Compatibility
Additive only; no existing signature or behavior changes. Like
socket_cookie(), the method exists on unix only. On Windows the digest stores a raw socket instead; I did not add an accessor for it, but can if wanted.Tests
raw_fd_returns_the_socket_fdinprotocols/digest.rs, in the existing Linux-only test module next to thesocket_cookie()tests: for a connected client and an accepted serverTcpStream,raw_fd()returns the same fd asas_raw_fd().Checks run locally (Debian 12, x86_64), following
.github/workflows/build.yml:cargo +1.97.1 fmt --all -- --check: cleancargo +1.97.1 clippy --all-targets --all -- --allow=unknown-lints --deny=warnings: cleancargo +1.97.1 test -p pingora-core: all pass excepttest_h2_late_frames_on_cancelled_streams_keep_connection, which also fails onmainhere and is skipped in CIcargo +1.85.0 check -p pingora-core: cleanI did not run the pingora-proxy test suite.
🤖 Generated with Claude Code