From 19b5faf6e103b1894f9af04d2cd7dc620a6c69ac Mon Sep 17 00:00:00 2001 From: Almas Abdrazak Date: Wed, 18 Feb 2026 15:42:26 -0800 Subject: [PATCH 1/4] JAVA-5907 --- .evergreen/run-tests.sh | 2 +- .../src/test/unit/util/ThreadTestHelpers.java | 2 +- .../GridFSMultiFileDownloadBenchmark.java | 6 ++-- .../GridFSMultiFileUploadBenchmark.java | 2 +- .../benchmarks/MultiFileExportBenchmark.java | 6 ++-- .../benchmarks/MultiFileImportBenchmark.java | 4 +-- .../framework/MongoCryptBenchmarkRunner.java | 2 +- .../connection/DefaultConnectionPool.java | 2 +- .../async/AsynchronousTlsChannel.java | 28 +++++++++---------- .../async/AsynchronousTlsChannelGroup.java | 15 ++++++++-- .../connection/DefaultConnectionPoolTest.java | 4 +-- ...tClientSideOperationsTimeoutProseTest.java | 6 ++-- 12 files changed, 44 insertions(+), 35 deletions(-) diff --git a/.evergreen/run-tests.sh b/.evergreen/run-tests.sh index 10bd5bc107d..385cd1aedcc 100755 --- a/.evergreen/run-tests.sh +++ b/.evergreen/run-tests.sh @@ -136,6 +136,6 @@ echo "Running tests with Java ${JAVA_VERSION}" --stacktrace --info --continue ${TESTS} | tee -a logs.txt if grep -q 'LEAK:' logs.txt ; then - echo "Netty Leak detected, please inspect build log" + echo -e "\033[31m!!!!Netty Leak detected, please inspect build log!!!\033[0m" exit 1 fi diff --git a/bson/src/test/unit/util/ThreadTestHelpers.java b/bson/src/test/unit/util/ThreadTestHelpers.java index e2115da079f..2428ee9074e 100644 --- a/bson/src/test/unit/util/ThreadTestHelpers.java +++ b/bson/src/test/unit/util/ThreadTestHelpers.java @@ -41,7 +41,7 @@ public static void executeAll(final Runnable... runnables) { CountDownLatch latch = new CountDownLatch(runnables.length); List failures = Collections.synchronizedList(new ArrayList<>()); for (final Runnable runnable : runnables) { - service.submit(() -> { + service.execute(() -> { try { runnable.run(); } catch (Throwable e) { diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/GridFSMultiFileDownloadBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/GridFSMultiFileDownloadBenchmark.java index e39c0fb46ba..f8f66fe8b90 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/GridFSMultiFileDownloadBenchmark.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/GridFSMultiFileDownloadBenchmark.java @@ -97,7 +97,7 @@ public void run() throws Exception { CountDownLatch latch = new CountDownLatch(50); for (int i = 0; i < 50; i++) { - gridFSService.submit(exportFile(latch, i)); + gridFSService.execute(exportFile(latch, i)); } latch.await(1, TimeUnit.MINUTES); @@ -107,7 +107,7 @@ private Runnable exportFile(final CountDownLatch latch, final int fileId) { return () -> { UnsafeByteArrayOutputStream outputStream = new UnsafeByteArrayOutputStream(5242880); bucket.downloadToStream(GridFSMultiFileDownloadBenchmark.this.getFileName(fileId), outputStream); - fileService.submit(() -> { + fileService.execute(() -> { try { FileOutputStream fos = new FileOutputStream(new File(tempDirectory, String.format("%02d", fileId) + ".txt")); fos.write(outputStream.getByteArray()); @@ -124,7 +124,7 @@ private void importFiles() throws Exception { CountDownLatch latch = new CountDownLatch(50); for (int i = 0; i < 50; i++) { - fileService.submit(importFile(latch, i)); + fileService.execute(importFile(latch, i)); } latch.await(1, TimeUnit.MINUTES); diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/GridFSMultiFileUploadBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/GridFSMultiFileUploadBenchmark.java index cefdc7eaf1c..e2ee177847d 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/GridFSMultiFileUploadBenchmark.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/GridFSMultiFileUploadBenchmark.java @@ -75,7 +75,7 @@ public void run() throws Exception { CountDownLatch latch = new CountDownLatch(50); for (int i = 0; i < 50; i++) { - fileService.submit(importFile(latch, i)); + fileService.execute(importFile(latch, i)); } latch.await(1, TimeUnit.MINUTES); diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/MultiFileExportBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/MultiFileExportBenchmark.java index 30c74084419..d57829de45b 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/MultiFileExportBenchmark.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/MultiFileExportBenchmark.java @@ -109,7 +109,7 @@ public void run() throws Exception { CountDownLatch latch = new CountDownLatch(100); for (int i = 0; i < 100; i++) { - documentReadingService.submit(exportJsonFile(i, latch)); + documentReadingService.execute(exportJsonFile(i, latch)); } latch.await(1, TimeUnit.MINUTES); @@ -125,7 +125,7 @@ private Runnable exportJsonFile(final int fileId, final CountDownLatch latch) { List documents = collection.find(new BsonDocument("fileId", new BsonInt32(fileId))) .batchSize(5000) .into(new ArrayList<>(5000)); - fileWritingService.submit(writeJsonFile(fileId, documents, latch)); + fileWritingService.execute(writeJsonFile(fileId, documents, latch)); }; } @@ -154,7 +154,7 @@ private void importJsonFiles() throws InterruptedException { for (int i = 0; i < 100; i++) { int fileId = i; - importService.submit(() -> { + importService.execute(() -> { String resourcePath = "parallel/ldjson_multi/ldjson" + String.format("%03d", fileId) + ".txt"; try (BufferedReader reader = new BufferedReader(readFromRelativePath(resourcePath), 1024 * 64)) { String json; diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/MultiFileImportBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/MultiFileImportBenchmark.java index 03d1a721bee..d7afc54496d 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/MultiFileImportBenchmark.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/MultiFileImportBenchmark.java @@ -86,7 +86,7 @@ public void run() throws InterruptedException { CountDownLatch latch = new CountDownLatch(500); for (int i = 0; i < 100; i++) { - fileReadingService.submit(importJsonFile(latch, i)); + fileReadingService.execute(importJsonFile(latch, i)); } latch.await(1, TimeUnit.MINUTES); @@ -104,7 +104,7 @@ private Runnable importJsonFile(final CountDownLatch latch, final int fileId) { documents.add(document); if (documents.size() == 1000) { List documentsToInsert = documents; - documentWritingService.submit(() -> { + documentWritingService.execute(() -> { collection.insertMany(documentsToInsert, new InsertManyOptions().ordered(false)); latch.countDown(); }); diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/framework/MongoCryptBenchmarkRunner.java b/driver-benchmarks/src/main/com/mongodb/benchmark/framework/MongoCryptBenchmarkRunner.java index 718ab9f21af..a6c623364db 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/framework/MongoCryptBenchmarkRunner.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/framework/MongoCryptBenchmarkRunner.java @@ -177,7 +177,7 @@ public List run() throws InterruptedException { for (int i = 0; i < threadCount; i++) { DecryptTask decryptTask = new DecryptTask(mongoCrypt, encrypted, NUM_SECS, doneSignal); decryptTasks.add(decryptTask); - executorService.submit(decryptTask); + executorService.execute(decryptTask); } // Await completion of all tasks. Tasks are expected to complete shortly after NUM_SECS. Time out `await` if time exceeds 2 * NUM_SECS. diff --git a/driver-core/src/main/com/mongodb/internal/connection/DefaultConnectionPool.java b/driver-core/src/main/com/mongodb/internal/connection/DefaultConnectionPool.java index 81a0e59e277..2339cf18b86 100644 --- a/driver-core/src/main/com/mongodb/internal/connection/DefaultConnectionPool.java +++ b/driver-core/src/main/com/mongodb/internal/connection/DefaultConnectionPool.java @@ -1321,7 +1321,7 @@ private boolean initUnlessClosed() { boolean result = true; if (state == State.NEW) { worker = Executors.newSingleThreadExecutor(new DaemonThreadFactory("AsyncGetter")); - worker.submit(() -> runAndLogUncaught(this::workerRun)); + worker.execute(() -> runAndLogUncaught(this::workerRun)); state = State.INITIALIZED; } else if (state == State.CLOSED) { result = false; diff --git a/driver-core/src/main/com/mongodb/internal/connection/tlschannel/async/AsynchronousTlsChannel.java b/driver-core/src/main/com/mongodb/internal/connection/tlschannel/async/AsynchronousTlsChannel.java index 04114318f92..c1e3f067335 100644 --- a/driver-core/src/main/com/mongodb/internal/connection/tlschannel/async/AsynchronousTlsChannel.java +++ b/driver-core/src/main/com/mongodb/internal/connection/tlschannel/async/AsynchronousTlsChannel.java @@ -98,8 +98,8 @@ public void read(ByteBuffer dst, A attach, CompletionHandler group.submit(() -> handler.completed((int) c, attach)), - e -> group.submit(() -> handler.failed(e, attach))); + c -> group.execute(() -> handler.completed((int) c, attach)), + e -> group.execute(() -> handler.failed(e, attach))); } @Override @@ -119,8 +119,8 @@ public void read( new ByteBufferSet(dst), timeout, unit, - c -> group.submit(() -> handler.completed((int) c, attach)), - e -> group.submit(() -> handler.failed(e, attach))); + c -> group.execute(() -> handler.completed((int) c, attach)), + e -> group.execute(() -> handler.failed(e, attach))); } @Override @@ -145,8 +145,8 @@ public void read( bufferSet, timeout, unit, - c -> group.submit(() -> handler.completed(c, attach)), - e -> group.submit(() -> handler.failed(e, attach))); + c -> group.execute(() -> handler.completed(c, attach)), + e -> group.execute(() -> handler.failed(e, attach))); } @Override @@ -185,8 +185,8 @@ public void write(ByteBuffer src, A attach, CompletionHandler group.submit(() -> handler.completed((int) c, attach)), - e -> group.submit(() -> handler.failed(e, attach))); + c -> group.execute(() -> handler.completed((int) c, attach)), + e -> group.execute(() -> handler.failed(e, attach))); } @Override @@ -205,8 +205,8 @@ public void write( new ByteBufferSet(src), timeout, unit, - c -> group.submit(() -> handler.completed((int) c, attach)), - e -> group.submit(() -> handler.failed(e, attach))); + c -> group.execute(() -> handler.completed((int) c, attach)), + e -> group.execute(() -> handler.failed(e, attach))); } @Override @@ -228,8 +228,8 @@ public void write( bufferSet, timeout, unit, - c -> group.submit(() -> handler.completed(c, attach)), - e -> group.submit(() -> handler.failed(e, attach))); + c -> group.execute(() -> handler.completed(c, attach)), + e -> group.execute(() -> handler.failed(e, attach))); } @Override @@ -251,11 +251,11 @@ public Future write(ByteBuffer src) { } private void completeWithZeroInt(A attach, CompletionHandler handler) { - group.submit(() -> handler.completed(0, attach)); + group.execute(() -> handler.completed(0, attach)); } private void completeWithZeroLong(A attach, CompletionHandler handler) { - group.submit(() -> handler.completed(0L, attach)); + group.execute(() -> handler.completed(0L, attach)); } /** diff --git a/driver-core/src/main/com/mongodb/internal/connection/tlschannel/async/AsynchronousTlsChannelGroup.java b/driver-core/src/main/com/mongodb/internal/connection/tlschannel/async/AsynchronousTlsChannelGroup.java index d9b1420a6e3..f8e3a69e9ba 100644 --- a/driver-core/src/main/com/mongodb/internal/connection/tlschannel/async/AsynchronousTlsChannelGroup.java +++ b/driver-core/src/main/com/mongodb/internal/connection/tlschannel/async/AsynchronousTlsChannelGroup.java @@ -43,6 +43,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.concurrent.LinkedBlockingQueue; @@ -65,7 +66,7 @@ * instance of this class is a singleton-like object that manages a thread pool that makes it * possible to run a group of asynchronous channels. */ -public class AsynchronousTlsChannelGroup { +public class AsynchronousTlsChannelGroup implements Executor { private static final Logger LOGGER = Loggers.getLogger("connection.tls"); @@ -224,8 +225,16 @@ public AsynchronousTlsChannelGroup(@Nullable final ExecutorService executorServi selectorThread.start(); } - void submit(final Runnable r) { - executor.submit(r); + + @Override + public void execute(final Runnable r) { + executor.execute(()->{ + try { + r.run(); + } catch (Throwable t) { + LOGGER.error(null, t); + } + }); } RegisteredSocket registerSocket(TlsChannel reader, SocketChannel socketChannel) { diff --git a/driver-core/src/test/functional/com/mongodb/internal/connection/DefaultConnectionPoolTest.java b/driver-core/src/test/functional/com/mongodb/internal/connection/DefaultConnectionPoolTest.java index fc5926b3bad..81e778b4a61 100644 --- a/driver-core/src/test/functional/com/mongodb/internal/connection/DefaultConnectionPoolTest.java +++ b/driver-core/src/test/functional/com/mongodb/internal/connection/DefaultConnectionPoolTest.java @@ -127,7 +127,7 @@ public void shouldThrowOnTimeout() throws InterruptedException { // when TimeoutTrackingConnectionGetter connectionGetter = new TimeoutTrackingConnectionGetter(provider, timeoutSettings); - cachedExecutor.submit(connectionGetter); + cachedExecutor.execute(connectionGetter); connectionGetter.getLatch().await(); @@ -152,7 +152,7 @@ public void shouldNotUseMaxAwaitTimeMSWhenTimeoutMsIsSet() throws InterruptedExc // when TimeoutTrackingConnectionGetter connectionGetter = new TimeoutTrackingConnectionGetter(provider, timeoutSettings); - cachedExecutor.submit(connectionGetter); + cachedExecutor.execute(connectionGetter); sleep(70); // wait for more than maxWaitTimeMS but less than timeoutMs. internalConnection.close(); diff --git a/driver-sync/src/test/functional/com/mongodb/client/AbstractClientSideOperationsTimeoutProseTest.java b/driver-sync/src/test/functional/com/mongodb/client/AbstractClientSideOperationsTimeoutProseTest.java index fa39a6d3a06..7828ecde684 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/AbstractClientSideOperationsTimeoutProseTest.java +++ b/driver-sync/src/test/functional/com/mongodb/client/AbstractClientSideOperationsTimeoutProseTest.java @@ -816,7 +816,7 @@ public void shouldIgnoreWaitQueueTimeoutMSWhenTimeoutMsIsSet() { + " }" + "}"); - executor.submit(() -> collection.find().first()); + executor.execute(() -> collection.find().first()); sleep(150); //when && then @@ -851,7 +851,7 @@ public void shouldThrowOperationTimeoutExceptionWhenConnectionIsNotAvailableAndT + " }" + "}"); - executor.submit(() -> collection.withTimeout(0, TimeUnit.MILLISECONDS).find().first()); + executor.execute(() -> collection.withTimeout(0, TimeUnit.MILLISECONDS).find().first()); sleep(100); //when && then @@ -886,7 +886,7 @@ public void shouldUseWaitQueueTimeoutMSWhenTimeoutIsNotSet() { + " }" + "}"); - executor.submit(() -> collection.find().first()); + executor.execute(() -> collection.find().first()); sleep(200); //when & then From e071c62079a7b045fb16f1a741c82c47d9ce846c Mon Sep 17 00:00:00 2001 From: Almas Abdrazak Date: Wed, 18 Feb 2026 15:42:26 -0800 Subject: [PATCH 2/4] JAVA-5907 use execute within executor service If we don't use the return value from executor then we should use `execute` instead of `submit` --- .evergreen/run-tests.sh | 2 +- .../src/test/unit/util/ThreadTestHelpers.java | 2 +- .../GridFSMultiFileDownloadBenchmark.java | 6 ++-- .../GridFSMultiFileUploadBenchmark.java | 2 +- .../benchmarks/MultiFileExportBenchmark.java | 6 ++-- .../benchmarks/MultiFileImportBenchmark.java | 4 +-- .../framework/MongoCryptBenchmarkRunner.java | 2 +- .../connection/DefaultConnectionPool.java | 2 +- .../async/AsynchronousTlsChannel.java | 28 +++++++++---------- .../async/AsynchronousTlsChannelGroup.java | 15 ++++++++-- .../connection/DefaultConnectionPoolTest.java | 4 +-- ...tClientSideOperationsTimeoutProseTest.java | 6 ++-- 12 files changed, 44 insertions(+), 35 deletions(-) diff --git a/.evergreen/run-tests.sh b/.evergreen/run-tests.sh index 10bd5bc107d..385cd1aedcc 100755 --- a/.evergreen/run-tests.sh +++ b/.evergreen/run-tests.sh @@ -136,6 +136,6 @@ echo "Running tests with Java ${JAVA_VERSION}" --stacktrace --info --continue ${TESTS} | tee -a logs.txt if grep -q 'LEAK:' logs.txt ; then - echo "Netty Leak detected, please inspect build log" + echo -e "\033[31m!!!!Netty Leak detected, please inspect build log!!!\033[0m" exit 1 fi diff --git a/bson/src/test/unit/util/ThreadTestHelpers.java b/bson/src/test/unit/util/ThreadTestHelpers.java index e2115da079f..2428ee9074e 100644 --- a/bson/src/test/unit/util/ThreadTestHelpers.java +++ b/bson/src/test/unit/util/ThreadTestHelpers.java @@ -41,7 +41,7 @@ public static void executeAll(final Runnable... runnables) { CountDownLatch latch = new CountDownLatch(runnables.length); List failures = Collections.synchronizedList(new ArrayList<>()); for (final Runnable runnable : runnables) { - service.submit(() -> { + service.execute(() -> { try { runnable.run(); } catch (Throwable e) { diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/GridFSMultiFileDownloadBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/GridFSMultiFileDownloadBenchmark.java index e39c0fb46ba..f8f66fe8b90 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/GridFSMultiFileDownloadBenchmark.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/GridFSMultiFileDownloadBenchmark.java @@ -97,7 +97,7 @@ public void run() throws Exception { CountDownLatch latch = new CountDownLatch(50); for (int i = 0; i < 50; i++) { - gridFSService.submit(exportFile(latch, i)); + gridFSService.execute(exportFile(latch, i)); } latch.await(1, TimeUnit.MINUTES); @@ -107,7 +107,7 @@ private Runnable exportFile(final CountDownLatch latch, final int fileId) { return () -> { UnsafeByteArrayOutputStream outputStream = new UnsafeByteArrayOutputStream(5242880); bucket.downloadToStream(GridFSMultiFileDownloadBenchmark.this.getFileName(fileId), outputStream); - fileService.submit(() -> { + fileService.execute(() -> { try { FileOutputStream fos = new FileOutputStream(new File(tempDirectory, String.format("%02d", fileId) + ".txt")); fos.write(outputStream.getByteArray()); @@ -124,7 +124,7 @@ private void importFiles() throws Exception { CountDownLatch latch = new CountDownLatch(50); for (int i = 0; i < 50; i++) { - fileService.submit(importFile(latch, i)); + fileService.execute(importFile(latch, i)); } latch.await(1, TimeUnit.MINUTES); diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/GridFSMultiFileUploadBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/GridFSMultiFileUploadBenchmark.java index cefdc7eaf1c..e2ee177847d 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/GridFSMultiFileUploadBenchmark.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/GridFSMultiFileUploadBenchmark.java @@ -75,7 +75,7 @@ public void run() throws Exception { CountDownLatch latch = new CountDownLatch(50); for (int i = 0; i < 50; i++) { - fileService.submit(importFile(latch, i)); + fileService.execute(importFile(latch, i)); } latch.await(1, TimeUnit.MINUTES); diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/MultiFileExportBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/MultiFileExportBenchmark.java index 30c74084419..d57829de45b 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/MultiFileExportBenchmark.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/MultiFileExportBenchmark.java @@ -109,7 +109,7 @@ public void run() throws Exception { CountDownLatch latch = new CountDownLatch(100); for (int i = 0; i < 100; i++) { - documentReadingService.submit(exportJsonFile(i, latch)); + documentReadingService.execute(exportJsonFile(i, latch)); } latch.await(1, TimeUnit.MINUTES); @@ -125,7 +125,7 @@ private Runnable exportJsonFile(final int fileId, final CountDownLatch latch) { List documents = collection.find(new BsonDocument("fileId", new BsonInt32(fileId))) .batchSize(5000) .into(new ArrayList<>(5000)); - fileWritingService.submit(writeJsonFile(fileId, documents, latch)); + fileWritingService.execute(writeJsonFile(fileId, documents, latch)); }; } @@ -154,7 +154,7 @@ private void importJsonFiles() throws InterruptedException { for (int i = 0; i < 100; i++) { int fileId = i; - importService.submit(() -> { + importService.execute(() -> { String resourcePath = "parallel/ldjson_multi/ldjson" + String.format("%03d", fileId) + ".txt"; try (BufferedReader reader = new BufferedReader(readFromRelativePath(resourcePath), 1024 * 64)) { String json; diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/MultiFileImportBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/MultiFileImportBenchmark.java index 03d1a721bee..d7afc54496d 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/MultiFileImportBenchmark.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/MultiFileImportBenchmark.java @@ -86,7 +86,7 @@ public void run() throws InterruptedException { CountDownLatch latch = new CountDownLatch(500); for (int i = 0; i < 100; i++) { - fileReadingService.submit(importJsonFile(latch, i)); + fileReadingService.execute(importJsonFile(latch, i)); } latch.await(1, TimeUnit.MINUTES); @@ -104,7 +104,7 @@ private Runnable importJsonFile(final CountDownLatch latch, final int fileId) { documents.add(document); if (documents.size() == 1000) { List documentsToInsert = documents; - documentWritingService.submit(() -> { + documentWritingService.execute(() -> { collection.insertMany(documentsToInsert, new InsertManyOptions().ordered(false)); latch.countDown(); }); diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/framework/MongoCryptBenchmarkRunner.java b/driver-benchmarks/src/main/com/mongodb/benchmark/framework/MongoCryptBenchmarkRunner.java index 718ab9f21af..a6c623364db 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/framework/MongoCryptBenchmarkRunner.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/framework/MongoCryptBenchmarkRunner.java @@ -177,7 +177,7 @@ public List run() throws InterruptedException { for (int i = 0; i < threadCount; i++) { DecryptTask decryptTask = new DecryptTask(mongoCrypt, encrypted, NUM_SECS, doneSignal); decryptTasks.add(decryptTask); - executorService.submit(decryptTask); + executorService.execute(decryptTask); } // Await completion of all tasks. Tasks are expected to complete shortly after NUM_SECS. Time out `await` if time exceeds 2 * NUM_SECS. diff --git a/driver-core/src/main/com/mongodb/internal/connection/DefaultConnectionPool.java b/driver-core/src/main/com/mongodb/internal/connection/DefaultConnectionPool.java index 81a0e59e277..2339cf18b86 100644 --- a/driver-core/src/main/com/mongodb/internal/connection/DefaultConnectionPool.java +++ b/driver-core/src/main/com/mongodb/internal/connection/DefaultConnectionPool.java @@ -1321,7 +1321,7 @@ private boolean initUnlessClosed() { boolean result = true; if (state == State.NEW) { worker = Executors.newSingleThreadExecutor(new DaemonThreadFactory("AsyncGetter")); - worker.submit(() -> runAndLogUncaught(this::workerRun)); + worker.execute(() -> runAndLogUncaught(this::workerRun)); state = State.INITIALIZED; } else if (state == State.CLOSED) { result = false; diff --git a/driver-core/src/main/com/mongodb/internal/connection/tlschannel/async/AsynchronousTlsChannel.java b/driver-core/src/main/com/mongodb/internal/connection/tlschannel/async/AsynchronousTlsChannel.java index 04114318f92..c1e3f067335 100644 --- a/driver-core/src/main/com/mongodb/internal/connection/tlschannel/async/AsynchronousTlsChannel.java +++ b/driver-core/src/main/com/mongodb/internal/connection/tlschannel/async/AsynchronousTlsChannel.java @@ -98,8 +98,8 @@ public void read(ByteBuffer dst, A attach, CompletionHandler group.submit(() -> handler.completed((int) c, attach)), - e -> group.submit(() -> handler.failed(e, attach))); + c -> group.execute(() -> handler.completed((int) c, attach)), + e -> group.execute(() -> handler.failed(e, attach))); } @Override @@ -119,8 +119,8 @@ public void read( new ByteBufferSet(dst), timeout, unit, - c -> group.submit(() -> handler.completed((int) c, attach)), - e -> group.submit(() -> handler.failed(e, attach))); + c -> group.execute(() -> handler.completed((int) c, attach)), + e -> group.execute(() -> handler.failed(e, attach))); } @Override @@ -145,8 +145,8 @@ public void read( bufferSet, timeout, unit, - c -> group.submit(() -> handler.completed(c, attach)), - e -> group.submit(() -> handler.failed(e, attach))); + c -> group.execute(() -> handler.completed(c, attach)), + e -> group.execute(() -> handler.failed(e, attach))); } @Override @@ -185,8 +185,8 @@ public void write(ByteBuffer src, A attach, CompletionHandler group.submit(() -> handler.completed((int) c, attach)), - e -> group.submit(() -> handler.failed(e, attach))); + c -> group.execute(() -> handler.completed((int) c, attach)), + e -> group.execute(() -> handler.failed(e, attach))); } @Override @@ -205,8 +205,8 @@ public void write( new ByteBufferSet(src), timeout, unit, - c -> group.submit(() -> handler.completed((int) c, attach)), - e -> group.submit(() -> handler.failed(e, attach))); + c -> group.execute(() -> handler.completed((int) c, attach)), + e -> group.execute(() -> handler.failed(e, attach))); } @Override @@ -228,8 +228,8 @@ public void write( bufferSet, timeout, unit, - c -> group.submit(() -> handler.completed(c, attach)), - e -> group.submit(() -> handler.failed(e, attach))); + c -> group.execute(() -> handler.completed(c, attach)), + e -> group.execute(() -> handler.failed(e, attach))); } @Override @@ -251,11 +251,11 @@ public Future write(ByteBuffer src) { } private void completeWithZeroInt(A attach, CompletionHandler handler) { - group.submit(() -> handler.completed(0, attach)); + group.execute(() -> handler.completed(0, attach)); } private void completeWithZeroLong(A attach, CompletionHandler handler) { - group.submit(() -> handler.completed(0L, attach)); + group.execute(() -> handler.completed(0L, attach)); } /** diff --git a/driver-core/src/main/com/mongodb/internal/connection/tlschannel/async/AsynchronousTlsChannelGroup.java b/driver-core/src/main/com/mongodb/internal/connection/tlschannel/async/AsynchronousTlsChannelGroup.java index d9b1420a6e3..f8e3a69e9ba 100644 --- a/driver-core/src/main/com/mongodb/internal/connection/tlschannel/async/AsynchronousTlsChannelGroup.java +++ b/driver-core/src/main/com/mongodb/internal/connection/tlschannel/async/AsynchronousTlsChannelGroup.java @@ -43,6 +43,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.concurrent.LinkedBlockingQueue; @@ -65,7 +66,7 @@ * instance of this class is a singleton-like object that manages a thread pool that makes it * possible to run a group of asynchronous channels. */ -public class AsynchronousTlsChannelGroup { +public class AsynchronousTlsChannelGroup implements Executor { private static final Logger LOGGER = Loggers.getLogger("connection.tls"); @@ -224,8 +225,16 @@ public AsynchronousTlsChannelGroup(@Nullable final ExecutorService executorServi selectorThread.start(); } - void submit(final Runnable r) { - executor.submit(r); + + @Override + public void execute(final Runnable r) { + executor.execute(()->{ + try { + r.run(); + } catch (Throwable t) { + LOGGER.error(null, t); + } + }); } RegisteredSocket registerSocket(TlsChannel reader, SocketChannel socketChannel) { diff --git a/driver-core/src/test/functional/com/mongodb/internal/connection/DefaultConnectionPoolTest.java b/driver-core/src/test/functional/com/mongodb/internal/connection/DefaultConnectionPoolTest.java index fc5926b3bad..81e778b4a61 100644 --- a/driver-core/src/test/functional/com/mongodb/internal/connection/DefaultConnectionPoolTest.java +++ b/driver-core/src/test/functional/com/mongodb/internal/connection/DefaultConnectionPoolTest.java @@ -127,7 +127,7 @@ public void shouldThrowOnTimeout() throws InterruptedException { // when TimeoutTrackingConnectionGetter connectionGetter = new TimeoutTrackingConnectionGetter(provider, timeoutSettings); - cachedExecutor.submit(connectionGetter); + cachedExecutor.execute(connectionGetter); connectionGetter.getLatch().await(); @@ -152,7 +152,7 @@ public void shouldNotUseMaxAwaitTimeMSWhenTimeoutMsIsSet() throws InterruptedExc // when TimeoutTrackingConnectionGetter connectionGetter = new TimeoutTrackingConnectionGetter(provider, timeoutSettings); - cachedExecutor.submit(connectionGetter); + cachedExecutor.execute(connectionGetter); sleep(70); // wait for more than maxWaitTimeMS but less than timeoutMs. internalConnection.close(); diff --git a/driver-sync/src/test/functional/com/mongodb/client/AbstractClientSideOperationsTimeoutProseTest.java b/driver-sync/src/test/functional/com/mongodb/client/AbstractClientSideOperationsTimeoutProseTest.java index fa39a6d3a06..7828ecde684 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/AbstractClientSideOperationsTimeoutProseTest.java +++ b/driver-sync/src/test/functional/com/mongodb/client/AbstractClientSideOperationsTimeoutProseTest.java @@ -816,7 +816,7 @@ public void shouldIgnoreWaitQueueTimeoutMSWhenTimeoutMsIsSet() { + " }" + "}"); - executor.submit(() -> collection.find().first()); + executor.execute(() -> collection.find().first()); sleep(150); //when && then @@ -851,7 +851,7 @@ public void shouldThrowOperationTimeoutExceptionWhenConnectionIsNotAvailableAndT + " }" + "}"); - executor.submit(() -> collection.withTimeout(0, TimeUnit.MILLISECONDS).find().first()); + executor.execute(() -> collection.withTimeout(0, TimeUnit.MILLISECONDS).find().first()); sleep(100); //when && then @@ -886,7 +886,7 @@ public void shouldUseWaitQueueTimeoutMSWhenTimeoutIsNotSet() { + " }" + "}"); - executor.submit(() -> collection.find().first()); + executor.execute(() -> collection.find().first()); sleep(200); //when & then From bd0ac6729590823be1ee4836a9c0fa4ed0ff25f2 Mon Sep 17 00:00:00 2001 From: Almas Abdrazak Date: Sun, 22 Feb 2026 21:53:00 -0800 Subject: [PATCH 3/4] format --- .../tlschannel/async/AsynchronousTlsChannelGroup.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver-core/src/main/com/mongodb/internal/connection/tlschannel/async/AsynchronousTlsChannelGroup.java b/driver-core/src/main/com/mongodb/internal/connection/tlschannel/async/AsynchronousTlsChannelGroup.java index f8e3a69e9ba..5150149fa6a 100644 --- a/driver-core/src/main/com/mongodb/internal/connection/tlschannel/async/AsynchronousTlsChannelGroup.java +++ b/driver-core/src/main/com/mongodb/internal/connection/tlschannel/async/AsynchronousTlsChannelGroup.java @@ -228,7 +228,7 @@ public AsynchronousTlsChannelGroup(@Nullable final ExecutorService executorServi @Override public void execute(final Runnable r) { - executor.execute(()->{ + executor.execute(() -> { try { r.run(); } catch (Throwable t) { From b38c1affb0fb8ac1fc7364d97640c3a2e0a15a08 Mon Sep 17 00:00:00 2001 From: Almas Abdrazak Date: Sun, 22 Feb 2026 21:53:51 -0800 Subject: [PATCH 4/4] revert error log for netty leak --- .evergreen/run-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.evergreen/run-tests.sh b/.evergreen/run-tests.sh index 385cd1aedcc..10bd5bc107d 100755 --- a/.evergreen/run-tests.sh +++ b/.evergreen/run-tests.sh @@ -136,6 +136,6 @@ echo "Running tests with Java ${JAVA_VERSION}" --stacktrace --info --continue ${TESTS} | tee -a logs.txt if grep -q 'LEAK:' logs.txt ; then - echo -e "\033[31m!!!!Netty Leak detected, please inspect build log!!!\033[0m" + echo "Netty Leak detected, please inspect build log" exit 1 fi