From 44151f342055754c4455670fa3b557714a2b7981 Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Fri, 2 Apr 2021 20:11:07 +0800 Subject: [PATCH] check ctx to fix. (#841) --- functions.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/functions.go b/functions.go index 972fff39e..836c1bb0e 100644 --- a/functions.go +++ b/functions.go @@ -47,15 +47,15 @@ func StartInstance(configFormat string, configBytes []byte) (*Instance, error) { // // v2ray:api:stable func Dial(ctx context.Context, v *Instance, dest net.Destination) (net.Conn, error) { + if FromContext(ctx) == nil { + ctx = context.WithValue(ctx, v2rayKey, v) + } + dispatcher := v.GetFeature(routing.DispatcherType()) if dispatcher == nil { return nil, newError("routing.Dispatcher is not registered in V2Ray core") } - if ctx.Value(v2rayKey) == nil { - ctx = context.WithValue(ctx, v2rayKey, v) - } - r, err := dispatcher.(routing.Dispatcher).Dispatch(ctx, dest) if err != nil { return nil, err @@ -76,6 +76,10 @@ func Dial(ctx context.Context, v *Instance, dest net.Destination) (net.Conn, err // // v2ray:api:beta func DialUDP(ctx context.Context, v *Instance) (net.PacketConn, error) { + if FromContext(ctx) == nil { + ctx = context.WithValue(ctx, v2rayKey, v) + } + dispatcher := v.GetFeature(routing.DispatcherType()) if dispatcher == nil { return nil, newError("routing.Dispatcher is not registered in V2Ray core")