Skip to content

Commit

Permalink
[konnectivity-client] Close tunnel from conn.Close()
Browse files Browse the repository at this point in the history
  • Loading branch information
tallclair committed Sep 7, 2022
1 parent 866231b commit 6539562
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion konnectivity-client/pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,11 @@ func (t *grpcTunnel) DialContext(requestCtx context.Context, protocol, address s

klog.V(5).Infoln("DIAL_REQ sent to proxy server")

c := &conn{stream: t.stream, random: random}
c := &conn{
stream: t.stream,
random: random,
closeTunnel: t.closeTunnel,
}

select {
case res := <-resCh:
Expand Down Expand Up @@ -366,7 +370,10 @@ func (t *grpcTunnel) closeDial(dialID int64) {
if err := t.stream.Send(req); err != nil {
klog.V(5).InfoS("Failed to send DIAL_CLS", "err", err, "dialID", dialID)
}
t.closeTunnel()
}

func (t *grpcTunnel) closeTunnel() {
atomic.StoreUint32(&t.closing, 1)
t.clientConn.Close()
}
Expand Down
7 changes: 7 additions & 0 deletions konnectivity-client/pkg/client/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ type conn struct {
readCh chan []byte
closeCh chan string
rdata []byte

// closeTunnel is an optional callback to close the underlying grpc connection.
closeTunnel func()
}

var _ net.Conn = &conn{}
Expand Down Expand Up @@ -116,6 +119,10 @@ func (c *conn) SetWriteDeadline(t time.Time) error {
// proxy service to notify remote to drop the connection.
func (c *conn) Close() error {
klog.V(4).Infoln("closing connection")
if c.closeTunnel != nil {
defer c.closeTunnel()
}

var req *client.Packet
if c.connID != 0 {
req = &client.Packet{
Expand Down

0 comments on commit 6539562

Please sign in to comment.