Fix context api and document (#727)

* Fix Dial function crash instance when there is no instance context in the ctx

* check ctx to fix. (#841)

* Feat: core.ToContext(ctx, v) for ctx initialization (#852)

* remove exported API: toContext

* Remove unnecessary API

* rework document for API

* fix: make sure the ctx is propagated to connections by detached connection

Co-authored-by: Shelikhoo <xiaokangwang@outlook.com>
Co-authored-by: rurirei <72071920+rurirei@users.noreply.github.com>
This commit is contained in:
yuhan6665 2022-02-19 22:45:41 -05:00 committed by GitHub
parent cf1ee095a2
commit 496b2c02c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 3 deletions

View file

@ -17,6 +17,7 @@ import (
"github.com/xtls/xray-core/common/session"
"github.com/xtls/xray-core/common/signal/pubsub"
"github.com/xtls/xray-core/common/task"
"github.com/xtls/xray-core/core"
dns_feature "github.com/xtls/xray-core/features/dns"
"github.com/xtls/xray-core/features/routing"
"github.com/xtls/xray-core/transport/internet/udp"
@ -195,7 +196,7 @@ func (s *ClassicNameServer) sendQuery(ctx context.Context, domain string, client
for _, req := range reqs {
s.addPendingRequest(req)
b, _ := dns.PackMessage(req.msg)
udpCtx := context.Background()
udpCtx := core.ToBackgroundDetachedContext(ctx)
if inbound := session.InboundFromContext(ctx); inbound != nil {
udpCtx = session.ContextWithInbound(udpCtx, inbound)
}