Skip to content

Commit 2e1dc2d

Browse files
authored
net.websocket: close the socket when the TLS connect in dial_socket fails (#28263)
`Client.dial_socket` dials the TcpConn and then runs `ws.ssl_conn.connect(mut t, …)!`, so a failed TLS handshake propagates with the socket never closed — and since `ws.conn` is only assigned after dial_socket returns, nothing downstream can close it either. Against a small embedded TLS server every failed connect kept a half-open session on the peer until its own timeout, and a few in a row exhausted its pool. Close it there, and the peer's half with it.
1 parent 6a0fbf3 commit 2e1dc2d

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

  • vlib/net/websocket

vlib/net/websocket/io.v

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@ fn (mut ws Client) dial_socket() !&net.TcpConn {
8484
t.set_read_timeout(ws.read_timeout)
8585
t.set_write_timeout(ws.write_timeout)
8686
if ws.is_ssl {
87-
ws.ssl_conn.connect(mut t, ws.uri.hostname)!
87+
ws.ssl_conn.connect(mut t, ws.uri.hostname) or {
88+
// The TcpConn is not the client's yet, so nothing else can close it: a failed TLS
89+
// handshake would otherwise leak the connected socket, and the peer's half of it.
90+
t.close() or {}
91+
return err
92+
}
8893
}
8994
return t
9095
}

0 commit comments

Comments
 (0)