Skip to content

Commit 6e499cb

Browse files
committed
Expose configuring cassandra connect timeout through query string
Exposes the cassandra client's ConnectTimeout parameter through the cassandra database query string. The Cassandra client has a fairly aggressive connect timeout of 600ms, which can cause flakiness in certain network environments or in Cassandra-compatible clusters with a more complex process for establishing connections (i.e. ScyllaDB). The query timeout is already configurable and exposed, but does not impact the connect timeout in the gocql driver. This change allows for configurtion of both.
1 parent 0bc9734 commit 6e499cb

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

database/cassandra/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ system_schema table which comes with 3.X
2020
| `consistency` | ALL | Migration consistency
2121
| `protocol` | | Cassandra protocol version (3 or 4)
2222
| `timeout` | 1 minute | Migration timeout
23+
| `connect-timeout` | 600ms | Initial connection timeout to the cluster |
2324
| `username` | nil | Username to use when authenticating. |
2425
| `password` | nil | Password to use when authenticating. |
2526
| `sslcert` | | Cert file location. The file must contain PEM encoded data. |

database/cassandra/cassandra.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ func (c *Cassandra) Open(url string) (database.Driver, error) {
133133
}
134134
cluster.Timeout = timeout
135135
}
136+
if len(u.Query().Get("connect-timeout")) > 0 {
137+
var connectTimeout time.Duration
138+
connectTimeout, err = time.ParseDuration(u.Query().Get("connect-timeout"))
139+
if err != nil {
140+
return nil, err
141+
}
142+
cluster.ConnectTimeout = connectTimeout
143+
}
136144

137145
if len(u.Query().Get("sslmode")) > 0 {
138146
if u.Query().Get("sslmode") != "disable" {

0 commit comments

Comments
 (0)