grpc: cancel stream

This commit is contained in:
ginuerzh
2022-12-30 19:34:48 +08:00
parent bb106e2d89
commit 3b245ec381
2 changed files with 8 additions and 18 deletions

View File

@ -109,8 +109,10 @@ func (d *grpcDialer) Dial(ctx context.Context, addr string, opts ...dialer.DialO
d.clients[addr] = client
}
cli, err := client.TunnelX(context.Background(), d.md.path)
ctx2, cancel := context.WithCancel(context.Background())
cli, err := client.TunnelX(ctx2, d.md.path)
if err != nil {
cancel()
return nil, err
}
@ -118,6 +120,6 @@ func (d *grpcDialer) Dial(ctx context.Context, addr string, opts ...dialer.DialO
c: cli,
localAddr: &net.TCPAddr{},
remoteAddr: &net.TCPAddr{},
closed: make(chan struct{}),
cancelFunc: cancel,
}, nil
}