Skip to content

Commit 6248b7c

Browse files
authored
fix(retry): make RetryLogic executor threads daemon (#1660)
This update makes sure `RetryLogic` executor threads are daemon.
1 parent 7450d98 commit 6248b7c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

driver/src/main/java/org/neo4j/driver/internal/DriverFactory.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Set;
2929
import java.util.concurrent.Executors;
3030
import java.util.concurrent.ScheduledExecutorService;
31+
import java.util.concurrent.atomic.AtomicInteger;
3132
import java.util.function.Function;
3233
import java.util.function.Supplier;
3334
import java.util.stream.Collectors;
@@ -112,7 +113,7 @@ public final Driver newInstance(
112113
Supplier<Rediscovery> rediscoverySupplier) {
113114
requireNonNull(authTokenManager, "authTokenProvider must not be null");
114115

115-
var retryExecutor = eventLoopGroup != null ? eventLoopGroup : Executors.newSingleThreadScheduledExecutor();
116+
var retryExecutor = eventLoopGroup != null ? eventLoopGroup : retryScheduledExecutorService();
116117
var retryLogic = createRetryLogic(config.maxTransactionRetryTimeMillis(), retryExecutor, config.logging());
117118

118119
var metricsProvider = getOrCreateMetricsProvider(config, createClock());
@@ -128,6 +129,16 @@ public final Driver newInstance(
128129
rediscoverySupplier);
129130
}
130131

132+
private static ScheduledExecutorService retryScheduledExecutorService() {
133+
var nextId = new AtomicInteger(1);
134+
return Executors.newSingleThreadScheduledExecutor(runnable -> {
135+
var thread = new Thread(runnable);
136+
thread.setName("neo4jdriverretry-" + nextId.getAndIncrement());
137+
thread.setDaemon(true);
138+
return thread;
139+
});
140+
}
141+
131142
protected static MetricsProvider getOrCreateMetricsProvider(Config config, Clock clock) {
132143
var metricsAdapter = config.metricsAdapter();
133144
// This can actually only happen when someone mocks the config

0 commit comments

Comments
 (0)