-
Notifications
You must be signed in to change notification settings - Fork 31
doh: keep pooled conns shorter-lived than server idle-timeouts; h2 PING health-checks #242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ShiroiKuma0
wants to merge
1
commit into
celzero:n2
Choose a base branch
from
ShiroiKuma0:kojiki-doh-idle
base: n2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+18
−4
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,6 +54,7 @@ import ( | |
| "github.com/celzero/firestack/intra/xdns" | ||
| "github.com/cloudflare/odoh-go" | ||
| "github.com/miekg/dns" | ||
| "golang.org/x/net/http2" | ||
| ) | ||
|
|
||
| const ( | ||
|
|
@@ -304,16 +305,29 @@ func asDialContext(d protect.DialFn) func(context.Context, string, string) (net. | |
| } | ||
|
|
||
| func h2(d protect.DialFn, c *tls.Config) *http.Transport { | ||
| return &http.Transport{ | ||
| DialContext: asDialContext(d), | ||
| ForceAttemptHTTP2: true, | ||
| IdleConnTimeout: 3 * time.Minute, | ||
| tr := &http.Transport{ | ||
| DialContext: asDialContext(d), | ||
| ForceAttemptHTTP2: true, | ||
| // Some resolvers close idle DoH connections well under 30s (Quad9 measured at <=30s | ||
| // from a fixed network; Cloudflare survives >240s). With the previous 3m pool, any DNS | ||
| // lull longer than the server's idle window left only dead connections in the pool, and | ||
| // subsequent queries were written into them — hanging ~10s and dying with | ||
| // "unexpected EOF" / http-status 502 bursts (maxEOFTries retries often just pick the next | ||
| // corpse). Keep pooled connections shorter-lived than any observed server-side idle window. | ||
| IdleConnTimeout: 10 * time.Second, | ||
| TLSHandshakeTimeout: 7 * time.Second, | ||
| // Android's DNS-over-TLS sets it to 30s | ||
| ResponseHeaderTimeout: 20 * time.Second, | ||
| // SNI (hostname) must always be inferred from http-request | ||
| TLSClientConfig: c, | ||
| } | ||
| // Health-check h2 connections with PING frames so half-dead ones are evicted instead of | ||
| // eating a query first (net/http does not do this by default). | ||
| if t2, err := http2.ConfigureTransports(tr); err == nil && t2 != nil { | ||
| t2.ReadIdleTimeout = 10 * time.Second | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what these are required for. Just the 30s idle timeout seems sufficient...? |
||
| t2.PingTimeout = 5 * time.Second | ||
| } | ||
| return tr | ||
| } | ||
|
|
||
| // always called from a go-routine | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10s seems too low. Perhaps this could be et to 30s instead?