feat: add pooled connection reuse health check - #426
Open
StellarisW wants to merge 5 commits into
Open
Conversation
StellarisW
marked this pull request as ready for review
July 25, 2026 06:08
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.
Summary
Adds a Linux-only, owner-synchronized
(*TCPConnection).IsHealthyForReuse(ownerWaitTimeout)probe for idle pooled client connections.FDOperatorownership across the LinkBuffer inspection and a single non-consumingMSG_PEEK | MSG_DONTWAITsocket probe.EINTRas fail-closed instead of retrying indefinitely, so both owner acquisition and the socket probe are bounded.PollDetach→ asynchronousOnHuplifecycle window.netpoll.Connectioninterface.Safety boundary
This is a pre-write eligibility check, not a reservation protocol: it rejects staleness visible while probing, but a peer may still close after this method returns and before a later write.
Functional validation
The tests are contained in this repository and use real loopback TCP connections created through
NewDialer().DialConnection. The focused suite covers:ioread→InputAckhandoff window;PollDetachbefore asynchronousOnHuppublishes the closing state;ownerWaitTimeout, where the check fails closed and does not leave the operator owned;EINTR) nonblocking probe, which fails closed without retrying.Current-head commands run with Go 1.20.14 on Linux:
The full repository test suite passed, the timeout/EINTR-focused race lane passed all 20 repetitions, and
go vet ./...passed at netpoll head598bbe1df4d1772bceb7dffbb4bce6ade86dc905.Performance benchmark
BenchmarkTCPConnectionIsHealthyForReuseIdleis included inconnection_reuse_linux_test.go. It creates one real loopback TCP pair before timing, performs one warm-up check, resets the timer, and repeatedly invokesIsHealthyForReuse(1s)on that same idle connection. Every iteration fails the benchmark if the connection is classified as unhealthy.ns/opB/opallocs/opBenchmark machine
5.4.143.bsk.8-amd64;x86_640-31.20.14;GOMAXPROCS=4; loopback-only trafficThis benchmark measures the healthy idle
IsHealthyForReuse(1s)probe itself. It is not an application-throughput or production-network benchmark.Related work