Repository navigation
feat: add a warm delay option to pingBatch - #174
Merged
Merged
Conversation
A single HEAD on a new connection also times the TCP, proxy and TLS handshakes, so the delay comes out several times the round trip through the outbound. With warm set, each item sends two HEAD requests on one connection and reports the second; both share the configured timeout. The default stays one request on a new connection.
yiguodev
reviewed
Nov 20, 2026
yiguodev
left a comment
Collaborator
There was a problem hiding this comment.
I tested 4ad4a87 with go test ./... -count=1 and local HTTP servers. The suite passed, and both warm requests share the configured deadline. I found four things to address before merging.
- Warm probes can report a new connection as a success. When the first response sends
Connection: close, the transport opens a second TCP connection and the probe still returnssuccess: true. The reported delay can include a fresh handshake. Please ensure both requests use the same connection and define how warm probes handle redirects or unavailable keep-alive. Request loop - The default probe changes how it follows same-origin redirects. A local 302 test used two connections on
mainand one on this PR withwarm=false. SettingDisableKeepAlives: !warmwould preserve the existing default measurement. Transport setup - The exported Go signature breaks existing callers. Three-argument calls to
xray.PingBatchno longer compile. The JSONInvokefield remains optional. Please keep the existing Go signature and expose warm probing through a separate entry point. Function signature - The timeout test only stalls the first HEAD. It would pass even if the second HEAD received a fresh deadline. Please let the first request finish, then have the second exceed the remaining budget and assert the
11000timeout result. Timeout test
PingBatch keeps its signature and its request; PingBatchWarm runs the warm probe, and Invoke picks it when warm is set. A warm probe does not follow redirects, and the item fails when the second request cannot reuse the connection. The timeout test now lets the first request answer and has the second exceed the remaining budget.
Contributor
Author
|
Thanks for testing it. All four are fixed in 8c9efea, on top of the commit you reviewed.
|
Collaborator
|
Thanks for the update. I retested
I recommend fixing both before merging. |
The second HEAD now fails with 10000 instead of opening a new connection, so a stall on a replacement connection can no longer turn into 11000, and the server sees only one request. Both requests go through Transport.RoundTrip, so a redirect with a malformed Location is still the answer; credentials in the URL are still sent, as http.Client sends them for the default probe.
Contributor
Author
|
Thanks, both reproduced and fixed in 64ae49c.
|
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
A single HEAD on a new connection also times the TCP connect, the proxy handshake and the TLS handshake to the target, so the delay comes out several times the round trip through the outbound. With
warm, the second request reuses the connection and leaves those handshakes out, the way mihomo's unified delay works. Both requests share the configured timeout, and an item fails if either does.A warm probe sends both requests through
Transport.RoundTrip, so a redirect response is the answer, even with a malformedLocation, and each request stays one round trip. The second request never opens a new connection: when the first one was not kept alive, for example afterConnection: close, the item fails with10000instead of timing a fresh handshake. Credentials in the URL are sent as Basic auth, ashttp.Clientdoes for the default probe.PingBatchkeeps its signature and its request: one HEAD with keep-alive disabled, timed bynodep.PingHTTPRequest. Go callers get the warm probe fromPingBatchWarm, andInvokepicks it whenwarmis set. The10000/11000values, the result shape, the five-item limit, input order and per-item failure isolation stay as they are. The English and Chinese READMEs describe the flag.Evidence
After: with
warm, the same servers report 69, 55 and 141–174.TestPingBatchWarmTimesSecondRequestOnOneConnection: a slow first answer stays out of the delay, and both requests arrive on one connection.TestPingBatchWarmFailsWithoutKeepAlive: a server that sendsConnection: closeand stalls any further request gets10000and sees only one request.TestPingBatchRedirects: a same-origin 302 takes two connections by default, as onmain, and the warm probe answers with the redirect on one connection, also whenLocationis malformed.TestPingBatchSendsURLCredentials: both probes senduser:pass@from the URL with every request.TestPingBatchTimesOutWithinOneTimeout: by default a stalled HEAD reports11000. With warm, the first HEAD answers at 1.2 s and the second needs another 1.2 s of a 2 s timeout; it reports11000within that timeout after the server saw both requests on one connection. A fresh deadline for the second request makes this test fail.TestInvokePingBatchWarmTimesSecondRequest:warmreaches the batch throughInvoke.go test ./... -count=1,go vet,gofmtandgit diff --check.