mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-06-17 13:05:24 +00: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"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
core "github.com/v2fly/v2ray-core/v4"
|
||||||
|
|
||||||
"github.com/lucas-clemente/quic-go"
|
"github.com/lucas-clemente/quic-go"
|
||||||
"golang.org/x/net/dns/dnsmessage"
|
"golang.org/x/net/dns/dnsmessage"
|
||||||
"golang.org/x/net/http2"
|
"golang.org/x/net/http2"
|
||||||
|
@ -370,7 +372,7 @@ func (s *QUICNameServer) openSession(ctx context.Context) (quic.Session, error)
|
||||||
HandshakeIdleTimeout: handshakeIdleTimeout,
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@ import (
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
core "github.com/v2fly/v2ray-core/v4"
|
||||||
|
|
||||||
"golang.org/x/net/dns/dnsmessage"
|
"golang.org/x/net/dns/dnsmessage"
|
||||||
|
|
||||||
"github.com/v2fly/v2ray-core/v4/common"
|
"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 {
|
for _, req := range reqs {
|
||||||
s.addPendingRequest(req)
|
s.addPendingRequest(req)
|
||||||
b, _ := dns.PackMessage(req.msg)
|
b, _ := dns.PackMessage(req.msg)
|
||||||
udpCtx := ctx
|
udpCtx := core.ToBackgroundDetachedContext(ctx)
|
||||||
if inbound := session.InboundFromContext(ctx); inbound != nil {
|
if inbound := session.InboundFromContext(ctx); inbound != nil {
|
||||||
udpCtx = session.ContextWithInbound(udpCtx, inbound)
|
udpCtx = session.ContextWithInbound(udpCtx, inbound)
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,3 +61,11 @@ func mustToContext(ctx context.Context, v *Instance) context.Context {
|
||||||
}
|
}
|
||||||
return ctx
|
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