An issue has been identified in the asynchronous API where exceptions thrown in plain code during thenRun operations are not properly propagated to the completion callback.
The issue arises when we dispatch to an asynchronous method in a separate thread within thenRun, and in the subsequent thenRun, we execute plain code that can throw an exception. Exceptions thrown are not caught and passed to the completion callback, but instead escalate up the thread's exception handler, leaving the callback uninvoked.
Example Code:
beginAsync().thenRun(c -> { new Thread() { public void run() { c.complete(c); } }.start(); }).thenRun(callback -> { throw new RuntimeException("Error"); }).finish(userCallback);
Expected Result: The userCallback should be invoked with the thrown exception, indicating that an exception occurred.
Actual Result: userCallback is not called, and the exception is unhandled, propagating up to the thread handler instead.
Suggested fix: Modify the Async API to use finish instead of unsafeFinish to include error handling that ensures exceptions in the chain are captured and passed to the completion callback when are executed on a different thread.
- related to
-
JAVA-5558 Failure to propagate IO exceptions in Asynchronous callbacks
- Closed