[ASYNC-76] Exceptions cannot be captured by default uncaught exception handler Created: 02/Jul/14  Updated: 06/Aug/14  Resolved: 06/Aug/14

Status: Closed
Project: core.async
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Stuart Sierra Assignee: Stuart Sierra
Resolution: Completed Votes: 6
Labels: None

Attachments: Text File 0001-ASYNC-76-do-not-catch-exceptions-on-thread-pool.patch     Text File 0002-ASYNC-76-propagate-exceptions-with-tests.patch    
Patch: Code and Test
Approval: Ok


Both core.async thread pools have a try/catch which catches and prints exceptions thrown in callbacks. This prevents application code from using the built-in mechanisms of the JVM to handle exceptions on arbitrary threads, namely Thread.setDefaultUncaughtExceptionHandler

In addition, the pool for 'thread' and 'thread-call' does not close the channel when an exception is thrown, which may lead to deadlocks.

Current Patch: 0002-ASYNC-76-propagate-exceptions-with-tests.patch

Approach: For the callback/go thread pool, do not catch exceptions at all. For the 'thread' pool, remove the 'catch' and close the channel in a 'finally'.

Background: Printing exceptions was added shortly after changing the arity to the 'put!' callback, to aid in debugging, see commit 9fcae995. Prior to this, the 'thread-call' function has always dropped exceptions silently; see commit 0b8e6171.

Duplicate of ASYNC-71 and similar to ASYNC-61, both of which request that the thread pools dispatch errors to a handler function Var which application code can alter.

An earlier issue (no JIRA ticket) occurred when tasks were submitted to the ThreadPoolExecutor with .submit, which returns a Future, instead of .execute.

Comment by Timothy Baldridge [ 03/Jul/14 8:13 AM ]

These threads are created in a fixed size thread pool. Won't you need to set the exception handler on the Executor constructor instead of on the thread itself?

Comment by Stuart Sierra [ 03/Jul/14 8:18 AM ]

No, the default uncaught exception handler is global for the whole JVM. Thread.setDefaultUncaughtExceptionHandler is static.

The exception handler can be overridden on a per-thread or per-thread-group basis.

Comment by Alex Miller [ 06/Aug/14 10:23 AM ]

applied to master

Generated at Sun May 19 12:19:48 CDT 2019 using JIRA 4.4#649-r158309.