Skip to content

Commit 34b1a5c

Browse files
tomekl007olim7t
authored andcommitted
JAVA-2841: Raise timeouts during connection initialization
1 parent 29a6c9a commit 34b1a5c

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

changelog/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### 4.8.0 (in progress)
66

7+
- [improvement] JAVA-2841: Raise timeouts during connection initialization
78
- [bug] JAVA-2331: Unregister old metrics when a node gets removed or changes RPC address
89
- [improvement] JAVA-2850: Ignore credentials in secure connect bundle [DataStax Astra]
910
- [improvement] JAVA-2813: Don't fail when secure bundle is specified together with other options

core/src/main/java/com/datastax/oss/driver/api/core/config/OptionsMap.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ private void readObject(ObjectInputStream stream) throws InvalidObjectException
242242
}
243243

244244
protected static void fillWithDriverDefaults(OptionsMap map) {
245+
Duration initQueryTimeout = Duration.ofSeconds(5);
246+
245247
// Sorted by order of appearance in reference.conf:
246248

247249
// Skip CONFIG_RELOAD_INTERVAL because the map-based config doesn't need periodic reloading
@@ -255,8 +257,8 @@ protected static void fillWithDriverDefaults(OptionsMap map) {
255257
map.put(TypedDriverOption.LOAD_BALANCING_POLICY_SLOW_AVOIDANCE, true);
256258
map.put(TypedDriverOption.SESSION_LEAK_THRESHOLD, 4);
257259
map.put(TypedDriverOption.CONNECTION_CONNECT_TIMEOUT, Duration.ofSeconds(5));
258-
map.put(TypedDriverOption.CONNECTION_INIT_QUERY_TIMEOUT, Duration.ofMillis(500));
259-
map.put(TypedDriverOption.CONNECTION_SET_KEYSPACE_TIMEOUT, Duration.ofMillis(500));
260+
map.put(TypedDriverOption.CONNECTION_INIT_QUERY_TIMEOUT, initQueryTimeout);
261+
map.put(TypedDriverOption.CONNECTION_SET_KEYSPACE_TIMEOUT, initQueryTimeout);
260262
map.put(TypedDriverOption.CONNECTION_POOL_LOCAL_SIZE, 1);
261263
map.put(TypedDriverOption.CONNECTION_POOL_REMOTE_SIZE, 1);
262264
map.put(TypedDriverOption.CONNECTION_MAX_REQUESTS, 1024);
@@ -324,7 +326,7 @@ protected static void fillWithDriverDefaults(OptionsMap map) {
324326
map.put(TypedDriverOption.METRICS_NODE_EXPIRE_AFTER, Duration.ofHours(1));
325327
map.put(TypedDriverOption.SOCKET_TCP_NODELAY, true);
326328
map.put(TypedDriverOption.HEARTBEAT_INTERVAL, Duration.ofSeconds(30));
327-
map.put(TypedDriverOption.HEARTBEAT_TIMEOUT, Duration.ofMillis(500));
329+
map.put(TypedDriverOption.HEARTBEAT_TIMEOUT, initQueryTimeout);
328330
map.put(TypedDriverOption.METADATA_TOPOLOGY_WINDOW, Duration.ofSeconds(1));
329331
map.put(TypedDriverOption.METADATA_TOPOLOGY_MAX_EVENTS, 20);
330332
map.put(TypedDriverOption.METADATA_SCHEMA_ENABLED, true);
@@ -333,7 +335,7 @@ protected static void fillWithDriverDefaults(OptionsMap map) {
333335
map.put(TypedDriverOption.METADATA_SCHEMA_WINDOW, Duration.ofSeconds(1));
334336
map.put(TypedDriverOption.METADATA_SCHEMA_MAX_EVENTS, 20);
335337
map.put(TypedDriverOption.METADATA_TOKEN_MAP_ENABLED, true);
336-
map.put(TypedDriverOption.CONTROL_CONNECTION_TIMEOUT, Duration.ofMillis(500));
338+
map.put(TypedDriverOption.CONTROL_CONNECTION_TIMEOUT, initQueryTimeout);
337339
map.put(TypedDriverOption.CONTROL_CONNECTION_AGREEMENT_INTERVAL, Duration.ofMillis(200));
338340
map.put(TypedDriverOption.CONTROL_CONNECTION_AGREEMENT_TIMEOUT, Duration.ofSeconds(10));
339341
map.put(TypedDriverOption.CONTROL_CONNECTION_AGREEMENT_WARN, true);
@@ -342,7 +344,7 @@ protected static void fillWithDriverDefaults(OptionsMap map) {
342344
map.put(TypedDriverOption.REPREPARE_CHECK_SYSTEM_TABLE, false);
343345
map.put(TypedDriverOption.REPREPARE_MAX_STATEMENTS, 0);
344346
map.put(TypedDriverOption.REPREPARE_MAX_PARALLELISM, 100);
345-
map.put(TypedDriverOption.REPREPARE_TIMEOUT, Duration.ofMillis(500));
347+
map.put(TypedDriverOption.REPREPARE_TIMEOUT, initQueryTimeout);
346348
map.put(TypedDriverOption.NETTY_DAEMON, false);
347349
map.put(TypedDriverOption.NETTY_IO_SIZE, 0);
348350
map.put(TypedDriverOption.NETTY_IO_SHUTDOWN_QUIET_PERIOD, 2);

core/src/main/resources/reference.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ datastax-java-driver {
377377
# Modifiable at runtime: yes, the new value will be used for connections created after the
378378
# change.
379379
# Overridable in a profile: no
380-
init-query-timeout = 500 milliseconds
380+
init-query-timeout = 5 seconds
381381

382382
# The timeout to use when the driver changes the keyspace on a connection at runtime (this
383383
# happens when the client issues a `USE ...` query, and all connections belonging to the current

core/src/test/java/com/datastax/oss/driver/internal/core/config/typesafe/DefaultDriverConfigLoaderTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public void should_load_from_other_classpath_resource() {
185185
DriverExecutionProfile config = loader.getInitialConfig().getDefaultProfile();
186186
// From customApplication.conf:
187187
assertThat(config.getDuration(DefaultDriverOption.REQUEST_TIMEOUT))
188-
.isEqualTo(Duration.ofMillis(500));
188+
.isEqualTo(Duration.ofSeconds(5));
189189
// From customApplication.json:
190190
assertThat(config.getInt(DefaultDriverOption.REQUEST_PAGE_SIZE)).isEqualTo(2000);
191191
// From customApplication.properties:
@@ -204,7 +204,7 @@ public void should_load_from_file() {
204204
DriverExecutionProfile config = loader.getInitialConfig().getDefaultProfile();
205205
// From customApplication.conf:
206206
assertThat(config.getDuration(DefaultDriverOption.REQUEST_TIMEOUT))
207-
.isEqualTo(Duration.ofMillis(500));
207+
.isEqualTo(Duration.ofSeconds(5));
208208
// From reference.conf:
209209
assertThat(config.getString(DefaultDriverOption.REQUEST_SERIAL_CONSISTENCY))
210210
.isEqualTo(DefaultConsistencyLevel.SERIAL.name());
@@ -220,7 +220,7 @@ public void should_load_from_file_with_system_property() {
220220
DriverExecutionProfile config = loader.getInitialConfig().getDefaultProfile();
221221
// From customApplication.conf:
222222
assertThat(config.getDuration(DefaultDriverOption.REQUEST_TIMEOUT))
223-
.isEqualTo(Duration.ofMillis(500));
223+
.isEqualTo(Duration.ofSeconds(5));
224224
// From reference.conf:
225225
assertThat(config.getString(DefaultDriverOption.REQUEST_SERIAL_CONSISTENCY))
226226
.isEqualTo(DefaultConsistencyLevel.SERIAL.name());

0 commit comments

Comments
 (0)