Skip to content

Commit

Permalink
workaround: recover from "0rtt rejected"
Browse files Browse the repository at this point in the history
  • Loading branch information
IrineSistiana committed Sep 17, 2023
1 parent ae546cd commit a4364db
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pkg/upstream/doq/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const (
defaultDoQTimeout = time.Second * 5
dialTimeout = time.Second * 3
connectionLostThreshold = time.Second * 5
handshakeTimeout = time.Second * 3
)

var (
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit a4364db

Please sign in to comment.