From 396730534ca9254aacd84f576f03b4090dfb0ff8 Mon Sep 17 00:00:00 2001 From: JaeMan Park Date: Wed, 17 Jul 2024 16:20:32 +0900 Subject: [PATCH] Fix double closure of sockets for websocket_agent At websocket_agent, wsWrapper.Close() is executed twice, at deferred function and inside go routine. Call wsWrapper.Close() only at go routine that writes data to the wsWrapper. Also move tcpConn.Close() after io.Copy(...) to avoid confusion. --- pkg/cli/cli.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go index 7de7148f..9b316f7b 100644 --- a/pkg/cli/cli.go +++ b/pkg/cli/cli.go @@ -1272,7 +1272,6 @@ func runConnectionWebSocketAgentCommand(flags *ConnectFlags, c *command, args [] c.PrintErrf("Failed to accept ADB socket: %v", err) return err } - defer tcpConn.Close() // Connect to ADB proxy WebSocket // wss://127.0.0.1:1443/devices/cvd-1/adb @@ -1321,12 +1320,12 @@ func runConnectionWebSocketAgentCommand(flags *ConnectFlags, c *command, args [] pos: 0, buf: nil, } - defer wsWrapper.Close() go func() { io.Copy(wsWrapper, tcpConn) wsWrapper.Close() }() io.Copy(tcpConn, wsWrapper) + tcpConn.Close() return nil }