From 950990074668754f5631e88662460b37042deb3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Reis?= Date: Fri, 18 Jul 2025 16:13:34 +0100 Subject: [PATCH] Fix issue where a timeout closes the connection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As part of CASSGO-12 which was supposedly just removing deprecated code, the driver now closes connections when a timeout occurs which was unintended. This patch fixes this issue. patch by João Reis; reviewed by Bohdan Siryk and Lukasz Antoniak for CASSGO-87 --- CHANGELOG.md | 1 + conn.go | 17 ++++++----------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68166e39c..fb779d7dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,6 +67,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 #### 2.0.0 +- Driver closes connection when timeout occurs (CASSGO-87) - Do not set beta protocol flag when using v5 (CASSGO-88) #### 2.0.0-rc1 diff --git a/conn.go b/conn.go index 877c2aaec..b7f3723d8 100644 --- a/conn.go +++ b/conn.go @@ -199,8 +199,6 @@ type Conn struct { ctx context.Context cancel context.CancelFunc - timeouts int64 - logger StructuredLogger } @@ -753,12 +751,6 @@ func (c *Conn) releaseStream(call *callReq) { } } -func (c *Conn) handleTimeout() { - if atomic.AddInt64(&c.timeouts, 1) > 0 { - c.closeWithError(ErrTooManyTimeouts) - } -} - func (c *Conn) recvSegment(ctx context.Context) error { var ( frame []byte @@ -1339,7 +1331,6 @@ func (c *Conn) execInternal(ctx context.Context, req frameBuilder, tracer Tracer close(call.timeout) c.logger.Debug("Request timed out on connection.", newLogFieldString("host_id", c.host.HostID()), newLogFieldIp("addr", c.host.ConnectAddress())) - c.handleTimeout() return nil, ErrTimeoutNoResponse case <-ctxDone: c.logger.Debug("Request failed because context elapsed out on connection.", @@ -2004,9 +1995,13 @@ func (c *Conn) awaitSchemaAgreement(ctx context.Context) (err error) { } var ( - ErrQueryArgLength = errors.New("gocql: query argument length mismatch") ErrTimeoutNoResponse = errors.New("gocql: no response received from cassandra within timeout period") - ErrTooManyTimeouts = errors.New("gocql: too many query timeouts on the connection") ErrConnectionClosed = errors.New("gocql: connection closed waiting for response") ErrNoStreams = errors.New("gocql: no streams available on connection") + + // Deprecated: TimeoutLimit was removed so this is never returned by the driver now + ErrTooManyTimeouts = errors.New("gocql: too many query timeouts on the connection") + + // Deprecated: Never returned by the driver + ErrQueryArgLength = errors.New("gocql: query argument length mismatch") )