Skip to content

Commit 540cb3d

Browse files
committed
Fix issue where a timeout closes the connection
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
1 parent d79b595 commit 540cb3d

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6767

6868
#### 2.0.0
6969

70+
- Driver closes connection when timeout occurs (CASSGO-87)
7071
- Do not set beta protocol flag when using v5 (CASSGO-88)
7172

7273
#### 2.0.0-rc1

conn.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,6 @@ type Conn struct {
199199
ctx context.Context
200200
cancel context.CancelFunc
201201

202-
timeouts int64
203-
204202
logger StructuredLogger
205203
}
206204

@@ -753,12 +751,6 @@ func (c *Conn) releaseStream(call *callReq) {
753751
}
754752
}
755753

756-
func (c *Conn) handleTimeout() {
757-
if atomic.AddInt64(&c.timeouts, 1) > 0 {
758-
c.closeWithError(ErrTooManyTimeouts)
759-
}
760-
}
761-
762754
func (c *Conn) recvSegment(ctx context.Context) error {
763755
var (
764756
frame []byte
@@ -1339,7 +1331,6 @@ func (c *Conn) execInternal(ctx context.Context, req frameBuilder, tracer Tracer
13391331
close(call.timeout)
13401332
c.logger.Debug("Request timed out on connection.",
13411333
newLogFieldString("host_id", c.host.HostID()), newLogFieldIp("addr", c.host.ConnectAddress()))
1342-
c.handleTimeout()
13431334
return nil, ErrTimeoutNoResponse
13441335
case <-ctxDone:
13451336
c.logger.Debug("Request failed because context elapsed out on connection.",
@@ -2004,9 +1995,13 @@ func (c *Conn) awaitSchemaAgreement(ctx context.Context) (err error) {
20041995
}
20051996

20061997
var (
2007-
ErrQueryArgLength = errors.New("gocql: query argument length mismatch")
20081998
ErrTimeoutNoResponse = errors.New("gocql: no response received from cassandra within timeout period")
2009-
ErrTooManyTimeouts = errors.New("gocql: too many query timeouts on the connection")
20101999
ErrConnectionClosed = errors.New("gocql: connection closed waiting for response")
20112000
ErrNoStreams = errors.New("gocql: no streams available on connection")
2001+
2002+
// Deprecated: TimeoutLimit was removed so this is never returned by the driver now
2003+
ErrTooManyTimeouts = errors.New("gocql: too many query timeouts on the connection")
2004+
2005+
// Deprecated: Never returned by the driver
2006+
ErrQueryArgLength = errors.New("gocql: query argument length mismatch")
20122007
)

0 commit comments

Comments
 (0)