From 219dab0fc037dbcbc0fa904501b487ab4daebf79 Mon Sep 17 00:00:00 2001 From: Will Donnelly Date: Wed, 23 Oct 2024 13:51:36 -0500 Subject: [PATCH] client: Fix timeout reset during TLS handshake This commit fixes `(*client.Conn).writeAuthHandshake()` to use `packet.NewConnWithTimeout` instead of `packet.NewBufferedConn` when recreating the packet connection after switching TLS on. This preserves the connection read/write timeout settings which would otherwise be reset to zero. Since this code executes after some reads and writes have already taken place, and the packet connection code only sets a deadline when the timeout values are nonzero, the result was that previously when connecting using TLS and with a read and/or write timeout set, the connection would inevitably fail just one timeout-duration after being opened. This use of `packet.NewBufferedConn` appears to be the only place in the `client` package where a packet connection was recreated without the timeout configuration being plumbed through. --- client/auth.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/auth.go b/client/auth.go index 006f71e11..200009609 100644 --- a/client/auth.go +++ b/client/auth.go @@ -304,7 +304,7 @@ func (c *Conn) writeAuthHandshake() error { } currentSequence := c.Sequence - c.Conn = packet.NewBufferedConn(tlsConn, c.BufferSize) + c.Conn = packet.NewConnWithTimeout(tlsConn, c.ReadTimeout, c.WriteTimeout, c.BufferSize) c.Sequence = currentSequence }