mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 15:36:41 -05:00
fix: make sure the ctx is propagated to connections by detached connection
This commit is contained in:
parent
2e26cf6587
commit
d48cf1a648
@ -9,6 +9,8 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
core "github.com/v2fly/v2ray-core/v4"
|
||||
|
||||
"github.com/lucas-clemente/quic-go"
|
||||
"golang.org/x/net/dns/dnsmessage"
|
||||
"golang.org/x/net/http2"
|
||||
@ -370,7 +372,7 @@ func (s *QUICNameServer) openSession(ctx context.Context) (quic.Session, error)
|
||||
HandshakeIdleTimeout: handshakeIdleTimeout,
|
||||
}
|
||||
|
||||
session, err := quic.DialAddrContext(ctx, s.destination.NetAddr(), tlsConfig.GetTLSConfig(tls.WithNextProto("http/1.1", http2.NextProtoTLS, NextProtoDQ)), quicConfig)
|
||||
session, err := quic.DialAddrContext(core.ToBackgroundDetachedContext(ctx), s.destination.NetAddr(), tlsConfig.GetTLSConfig(tls.WithNextProto("http/1.1", http2.NextProtoTLS, NextProtoDQ)), quicConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
core "github.com/v2fly/v2ray-core/v4"
|
||||
|
||||
"golang.org/x/net/dns/dnsmessage"
|
||||
|
||||
"github.com/v2fly/v2ray-core/v4/common"
|
||||
@ -192,7 +194,7 @@ func (s *ClassicNameServer) sendQuery(ctx context.Context, domain string, client
|
||||
for _, req := range reqs {
|
||||
s.addPendingRequest(req)
|
||||
b, _ := dns.PackMessage(req.msg)
|
||||
udpCtx := ctx
|
||||
udpCtx := core.ToBackgroundDetachedContext(ctx)
|
||||
if inbound := session.InboundFromContext(ctx); inbound != nil {
|
||||
udpCtx = session.ContextWithInbound(udpCtx, inbound)
|
||||
}
|
||||
|
@ -61,3 +61,11 @@ func mustToContext(ctx context.Context, v *Instance) context.Context {
|
||||
}
|
||||
return ctx
|
||||
}
|
||||
|
||||
/* ToBackgroundDetachedContext create a detached context from another context
|
||||
Internal API
|
||||
*/
|
||||
func ToBackgroundDetachedContext(ctx context.Context) context.Context {
|
||||
instance := MustFromContext(ctx)
|
||||
return toContext(context.Background(), instance)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user