fix: DOQ blocked dns return result because DOQ goroutine leak
This commit is contained in:
parent
23bc231df3
commit
85c37b473a
1 changed files with 8 additions and 8 deletions
16
dns/doq.go
16
dns/doq.go
|
@ -93,7 +93,7 @@ func isActive(s quic.Connection) bool {
|
||||||
// getSession - opens or returns an existing quic.Connection
|
// getSession - opens or returns an existing quic.Connection
|
||||||
// useCached - if true and cached session exists, return it right away
|
// useCached - if true and cached session exists, return it right away
|
||||||
// otherwise - forcibly creates a new session
|
// 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
|
var session quic.Connection
|
||||||
dc.RLock()
|
dc.RLock()
|
||||||
session = dc.session
|
session = dc.session
|
||||||
|
@ -111,14 +111,14 @@ func (dc *quicClient) getSession() (quic.Connection, error) {
|
||||||
defer dc.Unlock()
|
defer dc.Unlock()
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
session, err = dc.openSession()
|
session, err = dc.openSession(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// This does not look too nice, but QUIC (or maybe quic-go)
|
// This does not look too nice, but QUIC (or maybe quic-go)
|
||||||
// doesn't seem stable enough.
|
// doesn't seem stable enough.
|
||||||
// Maybe retransmissions aren't fully implemented in quic-go?
|
// Maybe retransmissions aren't fully implemented in quic-go?
|
||||||
// Anyways, the simple solution is to make a second try when
|
// Anyways, the simple solution is to make a second try when
|
||||||
// it fails to open the QUIC session.
|
// it fails to open the QUIC session.
|
||||||
session, err = dc.openSession()
|
session, err = dc.openSession(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ func (dc *quicClient) getSession() (quic.Connection, error) {
|
||||||
return session, nil
|
return session, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dc *quicClient) openSession() (quic.Connection, error) {
|
func (dc *quicClient) openSession(ctx context.Context) (quic.Connection, error) {
|
||||||
tlsConfig := &tls.Config{
|
tlsConfig := &tls.Config{
|
||||||
InsecureSkipVerify: true,
|
InsecureSkipVerify: true,
|
||||||
NextProtos: []string{
|
NextProtos: []string{
|
||||||
|
@ -163,12 +163,12 @@ func (dc *quicClient) openSession() (quic.Connection, error) {
|
||||||
udpAddr := net.UDPAddr{IP: ip.AsSlice(), Port: p}
|
udpAddr := net.UDPAddr{IP: ip.AsSlice(), Port: p}
|
||||||
|
|
||||||
if dc.proxyAdapter == "" {
|
if dc.proxyAdapter == "" {
|
||||||
udp, err = dialer.ListenPacket(context.Background(), "udp", "")
|
udp, err = dialer.ListenPacket(ctx, "udp", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
conn, err := dialContextExtra(context.Background(), dc.proxyAdapter, "udp", ip, port)
|
conn, err := dialContextExtra(ctx, dc.proxyAdapter, "udp", ip, port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,7 @@ func (dc *quicClient) openSession() (quic.Connection, error) {
|
||||||
udp = wrapConn
|
udp = wrapConn
|
||||||
}
|
}
|
||||||
|
|
||||||
session, err := quic.Dial(udp, &udpAddr, host, tlsConfig, quicConfig)
|
session, err := quic.DialContext(ctx, udp, &udpAddr, host, tlsConfig, quicConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to open QUIC session: %w", err)
|
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) {
|
func (dc *quicClient) openStream(ctx context.Context) (quic.Stream, error) {
|
||||||
session, err := dc.getSession()
|
session, err := dc.getSession(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue