luci-app-mosdns/mosdns/patches/108-workaround-recover-from-0rtt-rejected.patch
2023-09-18 14:59:04 +08:00

48 lines
1.3 KiB
Diff

From bc22fe05350994d031a1d915b8b1650d23062a52 Mon Sep 17 00:00:00 2001
From: Irine Sistiana <49315432+IrineSistiana@users.noreply.github.com>
Date: Sun, 17 Sep 2023 22:38:11 +0800
Subject: [PATCH 09/10] workaround: recover from "0rtt rejected"
---
pkg/upstream/doq/upstream.go | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/pkg/upstream/doq/upstream.go b/pkg/upstream/doq/upstream.go
index 43241f4..7b2d4e7 100644
--- a/pkg/upstream/doq/upstream.go
+++ b/pkg/upstream/doq/upstream.go
@@ -39,6 +39,7 @@ const (
defaultDoQTimeout = time.Second * 5
dialTimeout = time.Second * 3
connectionLostThreshold = time.Second * 5
+ handshakeTimeout = time.Second * 3
)
var (
@@ -160,7 +161,21 @@ func (u *Upstream) asyncDialConn() *lazyConn {
return
}
- c, err := u.t.Dial(ctx, ua, u.tlsConfig, u.quicConfig)
+ var c quic.Connection
+ ec, err := u.t.DialEarly(ctx, ua, u.tlsConfig, u.quicConfig)
+ if ec != nil {
+ // This is a workaround to
+ // 1. recover from strange 0rtt rejected err.
+ // 2. avoid NextConnection might block forever.
+ // TODO: Remove this workaround.
+ select {
+ case <-ctx.Done():
+ err = context.Cause(ctx)
+ ec.CloseWithError(0, "")
+ case <-ec.HandshakeComplete():
+ c = ec.NextConnection()
+ }
+ }
var closeC bool
lc.m.Lock()
--
2.34.8