-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
-
Java Drivers
-
Not Needed
-
The current implementation of the asynchronous API fails fails to propagate IOException from asynchronous IO to the callback, meaning users will never see an exception from IO operations. When throwTranslatedWriteException throws exception from thenRunTryCatchAsyncBlocks() method's error handler in the asynchronous API, the exception is propagated to a thread and not passed to the callback, rendering the error unobservable by a user.
This issue has been observed in the false positive test of InternalStreamConnectionSpecification (should notify all asynchronous writers of an exception), which aims to notify all asynchronous writers of an exception but takes an excessively long time (approximately 3 minutes) to complete.
The following example code mimics the issue and illustrates the error handling in the current implementation:
SingleResultCallback<Void> callback = (v, e) -> { if (e != null) { System.err.println("Error " + e); } else { System.err.println("Done successfully"); } }; beginAsync().thenRun(c -> { c.complete(c); }).thenRunTryCatchAsyncBlocks(c -> { new Thread() { public void run() { c.completeExceptionally(new IOException("Socket timeout")); } }.start(); }, Throwable.class, (t, c) -> { throw new MongoSocketWriteException("Socket write error", null, t); }).finish(callback);