Skip to content

Commit eb084c8

Browse files
committed
Try to connect WebSocket and return error before send result to parent
When WebSocket connection error is occured, current implementation sends result as success becuase it tries to send result before reporting result. The error messahe also not shown because standard IOs are closed. Try to connect WebSocket before sending result to parent to fix this.
1 parent 29fda9c commit eb084c8

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

pkg/cli/cli.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,22 @@ func runConnectionWebSocketAgentCommand(flags *ConnectFlags, c *command, args []
12741274
}
12751275
defer tcpConn.Close()
12761276

1277+
// Connect to ADB proxy WebSocket
1278+
// wss://127.0.0.1:1443/devices/cvd-1/adb
1279+
// Since the operator is self-signed, skip verifying cert
1280+
dialer := websocket.Dialer{
1281+
TLSClientConfig: &tls.Config{
1282+
InsecureSkipVerify: true,
1283+
},
1284+
}
1285+
device := args[0]
1286+
wsUrl := fmt.Sprintf("%s/devices/%s/adb", wsRoot, device)
1287+
wsConn, _, err := dialer.Dial(wsUrl, nil)
1288+
if err != nil {
1289+
log.Fatal("Failed to connect ", wsUrl, ": ", err)
1290+
return err
1291+
}
1292+
12771293
// Send connect result to the parent
12781294
result := ConnStatus{
12791295
ADB: ForwarderState{
@@ -1299,22 +1315,6 @@ func runConnectionWebSocketAgentCommand(flags *ConnectFlags, c *command, args []
12991315
cerr.Close()
13001316
}
13011317

1302-
// Connect to ADB proxy WebSocket
1303-
// wss://127.0.0.1:1443/devices/cvd-1/adb
1304-
// Since the operator is self-signed, skip verifying cert
1305-
dialer := websocket.Dialer{
1306-
TLSClientConfig: &tls.Config{
1307-
InsecureSkipVerify: true,
1308-
},
1309-
}
1310-
device := args[0]
1311-
wsUrl := fmt.Sprintf("%s/devices/%s/adb", wsRoot, device)
1312-
wsConn, _, err := dialer.Dial(wsUrl, nil)
1313-
if err != nil {
1314-
log.Fatal("Failed to connect ", wsUrl, ": ", err)
1315-
return err
1316-
}
1317-
13181318
// Redirect WebSocket to ADB TCP port
13191319
wsWrapper := &wsIoWrapper{
13201320
wsConn: wsConn,

0 commit comments

Comments
 (0)