Bug 56492 - Avoid eclipse debugger pausing on uncaught exceptions when tomcat renews its threads
Summary: Avoid eclipse debugger pausing on uncaught exceptions when tomcat renews its ...
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 8.0.x-trunk
Hardware: All All
: P2 enhancement (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-05 21:10 UTC by Sylvain Laurent
Modified: 2020-08-12 20:13 UTC (History)
0 users



Attachments
proposed patch for tomcat 8 (5.58 KB, patch)
2014-05-05 21:10 UTC, Sylvain Laurent
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sylvain Laurent 2014-05-05 21:10:01 UTC
Currently when tomcat is run with eclipse debugger and a Context is reloaded, each thread that exits (because of the feature to renew threads) triggers a breakpoint in eclipse if its "Suspend execution on uncaught exceptions" is enabled (which is the default).

This has been reported to eclipse : https://bugs.eclipse.org/bugs/show_bug.cgi?id=384073 which closed it without change in eclipse.

This also has a high number of votes on http://stackoverflow.com/questions/6290470/eclipse-debugger-always-blocks-on-threadpoolexecutor-without-any-obvious-excepti and is deemed as quite annoying.

The attached patch fixes tomcat by not letting the exception go out of Thread.run() and thus trigger the debugger. Instead, a custom exception is thrown to have the Thread go out of the ThreadPool and then caught and swallowed before Thread.run() returns.

Patch is against tomcat 8 trunk and passes checkstyle and NIO2 tests.
Comment 1 Sylvain Laurent 2014-05-05 21:10:45 UTC
Created attachment 31592 [details]
proposed patch for tomcat 8
Comment 2 Christopher Schultz 2014-05-06 17:46:22 UTC
My question would be why there is an exception thrown here to handle this case at all. Instead, why not check to see if we should die cleanly, then emit the recycling message to the log and simply exit the run method?

I don't understand why an exception is being used here at all.
Comment 3 Sylvain Laurent 2014-05-06 19:55:51 UTC
(In reply to Christopher Schultz from comment #2)
> My question would be why there is an exception thrown here to handle this
> case at all. Instead, why not check to see if we should die cleanly, then
> emit the recycling message to the log and simply exit the run method?
> 
> I don't understand why an exception is being used here at all.

Because actually in normal operation those threads never go out of java.util.concurrent.ThreadPoolExecutor.runWorker(Worker) unless there are more threads than the corePoolSize and the task queue is empty.

So, when I worked on the renewal of threads to avoid classloader leaks upon undeployment, the only way I found was to throw an exception in our implementation of ThreadPoolExecutor.afterExecute(Runnable, Throwable).

Is it OK for me to commit on tomcat 8 trunk?
Comment 4 Christopher Schultz 2014-05-07 19:11:57 UTC
Trunk is CTR, so fire away. If you wrote the original code, I can't think of a better person to refactor it :)
Comment 5 Sylvain Laurent 2014-05-07 21:06:22 UTC
committed to tomcat 8 trunk : r1593132

what about tomcat 7 ? is it still CTR as stated in https://wiki.apache.org/tomcat/TomcatVersions
Comment 6 Sylvain Laurent 2014-05-08 19:40:01 UTC
I merged to tomcat 7 : r1593392

The fix will be available in tomcat 7.0.54 and tomcat 8.0.6