From 12249c42030003a1b78e80cd0c8c2facf01fa6e4 Mon Sep 17 00:00:00 2001 From: Martin Sucha Date: Mon, 28 Aug 2023 10:03:16 +0200 Subject: [PATCH 1/2] Increase default timeouts Client timeouts need to be higher than server timeouts, so that work does not accumulate on the server with retries. This was not true by default, the gocql default timeout was lower than the Cassandra default timeout. Closes https://github.com/gocql/gocql/issues/1671 Closes https://github.com/gocql/gocql/issues/1701 --- CHANGELOG.md | 3 +++ cluster.go | 26 ++++++++++++++++++++------ cluster_test.go | 2 +- conn_test.go | 1 + 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 685f9931f..b704ae9b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 information about that every time this information is received. (#1714) ### Changed - Tracer created with NewTraceWriter now includes the thread information from trace events in the output. (#1716) +- Increased default timeouts so that they are higher than Cassandra default timeouts. + This should help prevent issues where a default configuration overloads a server using default timeouts + during retries. (#1701) ### Fixed diff --git a/cluster.go b/cluster.go index cf403dd6c..e4b6e4673 100644 --- a/cluster.go +++ b/cluster.go @@ -51,14 +51,28 @@ type ClusterConfig struct { // versions the protocol selected is not defined (ie, it can be any of the supported in the cluster) ProtoVersion int - // Connection timeout (default: 600ms) - // ConnectTimeout is used to set up the default dialer and is ignored if Dialer or HostDialer is provided. + // Timeout limits the time spent on the client side while executing a query. + // Specifically, query or batch execution will return an error if the client does not receive a response + // from the server within the Timeout period. + // Timeout is also used to configure the read timeout on the underlying network connection. + // Client Timeout should always be higher than the request timeouts configured on the server, + // so that retries don't overload the server. + // Timeout has a default value of 11 seconds, which is higher than default server timeout for most query types. + // Timeout is not applied to requests during initial connection setup, see ConnectTimeout. Timeout time.Duration - // Initial connection timeout, used during initial dial to server (default: 600ms) + // ConnectTimeout limits the time spent during connection setup. + // During initial connection setup, internal queries, AUTH requests will return an error if the client + // does not receive a response within the ConnectTimeout period. + // ConnectTimeout is applied to the connection setup queries independently. + // ConnectTimeout also limits the duration of dialing a new TCP connection + // in case there is no Dialer nor HostDialer configured. + // ConnectTimeout has a default value of 11 seconds. ConnectTimeout time.Duration - // Timeout for writing a query. Defaults to Timeout if not specified. + // WriteTimeout limits the time the driver waits to write a request to a network connection. + // WriteTimeout should be lower than or equal to Timeout. + // WriteTimeout defaults to the value of Timeout. WriteTimeout time.Duration // Port used when dialing. @@ -244,8 +258,8 @@ func NewCluster(hosts ...string) *ClusterConfig { cfg := &ClusterConfig{ Hosts: hosts, CQLVersion: "3.0.0", - Timeout: 600 * time.Millisecond, - ConnectTimeout: 600 * time.Millisecond, + Timeout: 11 * time.Second, + ConnectTimeout: 11 * time.Second, Port: 9042, NumConns: 2, Consistency: Quorum, diff --git a/cluster_test.go b/cluster_test.go index f7fe5acbf..0d580dbd4 100644 --- a/cluster_test.go +++ b/cluster_test.go @@ -10,7 +10,7 @@ import ( func TestNewCluster_Defaults(t *testing.T) { cfg := NewCluster() assertEqual(t, "cluster config cql version", "3.0.0", cfg.CQLVersion) - assertEqual(t, "cluster config timeout", 600*time.Millisecond, cfg.Timeout) + assertEqual(t, "cluster config timeout", 11*time.Second, cfg.Timeout) assertEqual(t, "cluster config port", 9042, cfg.Port) assertEqual(t, "cluster config num-conns", 2, cfg.NumConns) assertEqual(t, "cluster config consistency", Quorum, cfg.Consistency) diff --git a/conn_test.go b/conn_test.go index 42bdbb637..2e4c0ebb2 100644 --- a/conn_test.go +++ b/conn_test.go @@ -229,6 +229,7 @@ func TestStartupTimeout(t *testing.T) { // Set very long query connection timeout // so we know CreateSession() is using the ConnectTimeout cluster.Timeout = time.Second * 5 + cluster.ConnectTimeout = 600 * time.Millisecond // Create session should timeout during connect attempt _, err := cluster.CreateSession() From 34fdeebefcbf183ed7f916f931aa0586fdaa1b40 Mon Sep 17 00:00:00 2001 From: Martin Sucha Date: Mon, 28 Aug 2023 17:19:55 +0200 Subject: [PATCH 2/2] Update changelog for 1.6.0 --- CHANGELOG.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b704ae9b0..8dfb22828 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,19 +6,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +### Changed + +### Fixed + +## [1.6.0] - 2023-08-28 + ### Added - Added the InstaclustrPasswordAuthenticator to the list of default approved authenticators. (#1711) - Added the `com.scylladb.auth.SaslauthdAuthenticator` and `com.scylladb.auth.TransitionalAuthenticator` to the list of default approved authenticators. (#1712) - Added transferring Keyspace and Table names to the Query from the prepared response and updating information about that every time this information is received. (#1714) + ### Changed - Tracer created with NewTraceWriter now includes the thread information from trace events in the output. (#1716) - Increased default timeouts so that they are higher than Cassandra default timeouts. This should help prevent issues where a default configuration overloads a server using default timeouts - during retries. (#1701) - -### Fixed + during retries. (#1701, #1719) ## [1.5.2] - 2023-06-12