Skip to content

Commit 12249c4

Browse files
committed
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 #1671 Closes #1701
1 parent 7a686db commit 12249c4

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
information about that every time this information is received. (#1714)
1515
### Changed
1616
- Tracer created with NewTraceWriter now includes the thread information from trace events in the output. (#1716)
17+
- Increased default timeouts so that they are higher than Cassandra default timeouts.
18+
This should help prevent issues where a default configuration overloads a server using default timeouts
19+
during retries. (#1701)
1720

1821
### Fixed
1922

cluster.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,28 @@ type ClusterConfig struct {
5151
// versions the protocol selected is not defined (ie, it can be any of the supported in the cluster)
5252
ProtoVersion int
5353

54-
// Connection timeout (default: 600ms)
55-
// ConnectTimeout is used to set up the default dialer and is ignored if Dialer or HostDialer is provided.
54+
// Timeout limits the time spent on the client side while executing a query.
55+
// Specifically, query or batch execution will return an error if the client does not receive a response
56+
// from the server within the Timeout period.
57+
// Timeout is also used to configure the read timeout on the underlying network connection.
58+
// Client Timeout should always be higher than the request timeouts configured on the server,
59+
// so that retries don't overload the server.
60+
// Timeout has a default value of 11 seconds, which is higher than default server timeout for most query types.
61+
// Timeout is not applied to requests during initial connection setup, see ConnectTimeout.
5662
Timeout time.Duration
5763

58-
// Initial connection timeout, used during initial dial to server (default: 600ms)
64+
// ConnectTimeout limits the time spent during connection setup.
65+
// During initial connection setup, internal queries, AUTH requests will return an error if the client
66+
// does not receive a response within the ConnectTimeout period.
67+
// ConnectTimeout is applied to the connection setup queries independently.
68+
// ConnectTimeout also limits the duration of dialing a new TCP connection
69+
// in case there is no Dialer nor HostDialer configured.
70+
// ConnectTimeout has a default value of 11 seconds.
5971
ConnectTimeout time.Duration
6072

61-
// Timeout for writing a query. Defaults to Timeout if not specified.
73+
// WriteTimeout limits the time the driver waits to write a request to a network connection.
74+
// WriteTimeout should be lower than or equal to Timeout.
75+
// WriteTimeout defaults to the value of Timeout.
6276
WriteTimeout time.Duration
6377

6478
// Port used when dialing.
@@ -244,8 +258,8 @@ func NewCluster(hosts ...string) *ClusterConfig {
244258
cfg := &ClusterConfig{
245259
Hosts: hosts,
246260
CQLVersion: "3.0.0",
247-
Timeout: 600 * time.Millisecond,
248-
ConnectTimeout: 600 * time.Millisecond,
261+
Timeout: 11 * time.Second,
262+
ConnectTimeout: 11 * time.Second,
249263
Port: 9042,
250264
NumConns: 2,
251265
Consistency: Quorum,

cluster_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
func TestNewCluster_Defaults(t *testing.T) {
1111
cfg := NewCluster()
1212
assertEqual(t, "cluster config cql version", "3.0.0", cfg.CQLVersion)
13-
assertEqual(t, "cluster config timeout", 600*time.Millisecond, cfg.Timeout)
13+
assertEqual(t, "cluster config timeout", 11*time.Second, cfg.Timeout)
1414
assertEqual(t, "cluster config port", 9042, cfg.Port)
1515
assertEqual(t, "cluster config num-conns", 2, cfg.NumConns)
1616
assertEqual(t, "cluster config consistency", Quorum, cfg.Consistency)

conn_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ func TestStartupTimeout(t *testing.T) {
229229
// Set very long query connection timeout
230230
// so we know CreateSession() is using the ConnectTimeout
231231
cluster.Timeout = time.Second * 5
232+
cluster.ConnectTimeout = 600 * time.Millisecond
232233

233234
// Create session should timeout during connect attempt
234235
_, err := cluster.CreateSession()

0 commit comments

Comments
 (0)