fix: DOQ blocked dns return result because DOQ goroutine leak

This commit is contained in:
Skyxim 2022-06-12 21:41:01 +08:00
parent 23bc231df3
commit 85c37b473a

View file

@ -93,7 +93,7 @@ func isActive(s quic.Connection) bool {
// getSession - opens or returns an existing quic.Connection
// useCached - if true and cached session exists, return it right away
// otherwise - forcibly creates a new session
func (dc *quicClient) getSession() (quic.Connection, error) {
func (dc *quicClient) getSession(ctx context.Context) (quic.Connection, error) {
var session quic.Connection
dc.RLock()
session = dc.session
@ -111,14 +111,14 @@ func (dc *quicClient) getSession() (quic.Connection, error) {
defer dc.Unlock()
var err error
session, err = dc.openSession()
session, err = dc.openSession(ctx)
if err != nil {
// This does not look too nice, but QUIC (or maybe quic-go)
// doesn't seem stable enough.
// Maybe retransmissions aren't fully implemented in quic-go?
// Anyways, the simple solution is to make a second try when
// it fails to open the QUIC session.
session, err = dc.openSession()
session, err = dc.openSession(ctx)
if err != nil {
return nil, err
}
@ -127,7 +127,7 @@ func (dc *quicClient) getSession() (quic.Connection, error) {
return session, nil
}
func (dc *quicClient) openSession() (quic.Connection, error) {
func (dc *quicClient) openSession(ctx context.Context) (quic.Connection, error) {
tlsConfig := &tls.Config{
InsecureSkipVerify: true,
NextProtos: []string{
@ -163,12 +163,12 @@ func (dc *quicClient) openSession() (quic.Connection, error) {
udpAddr := net.UDPAddr{IP: ip.AsSlice(), Port: p}
if dc.proxyAdapter == "" {
udp, err = dialer.ListenPacket(context.Background(), "udp", "")
udp, err = dialer.ListenPacket(ctx, "udp", "")
if err != nil {
return nil, err
}
} else {
conn, err := dialContextExtra(context.Background(), dc.proxyAdapter, "udp", ip, port)
conn, err := dialContextExtra(ctx, dc.proxyAdapter, "udp", ip, port)
if err != nil {
return nil, err
}
@ -181,7 +181,7 @@ func (dc *quicClient) openSession() (quic.Connection, error) {
udp = wrapConn
}
session, err := quic.Dial(udp, &udpAddr, host, tlsConfig, quicConfig)
session, err := quic.DialContext(ctx, udp, &udpAddr, host, tlsConfig, quicConfig)
if err != nil {
return nil, fmt.Errorf("failed to open QUIC session: %w", err)
}
@ -190,7 +190,7 @@ func (dc *quicClient) openSession() (quic.Connection, error) {
}
func (dc *quicClient) openStream(ctx context.Context) (quic.Stream, error) {
session, err := dc.getSession()
session, err := dc.getSession(ctx)
if err != nil {
return nil, err
}