Bug 56724 - Restart Container background thread if it died unexpectedly
Summary: Restart Container background thread if it died unexpectedly
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 8.0.9
Hardware: PC All
: P2 enhancement (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2014-07-15 12:29 UTC by Konstantin Kolinko
Modified: 2019-08-09 17:28 UTC (History)
0 users

2014-07-15_tc8_56724_v1.patch (3.48 KB, patch)
2014-07-15 12:33 UTC, Konstantin Kolinko
Details | Diff
2014-07-18_tc8_56724_v2.patch (2.92 KB, patch)
2014-07-17 22:55 UTC, Konstantin Kolinko
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Konstantin Kolinko 2014-07-15 12:29:23 UTC
To address the issue that has been raised several times on the mailing lists, e.g.

"ContainerBackgroundProcessor and compounding OOMEs"

"Background thread died; no errors in log; invoking backgroundProcess via JMX has no effect"

I think it is OK to start a new background thread after some delay. If the start succeeds, it will be a new thread with its own (clean) stack.

It may help for StackOverflowError.
It might partially help with OutOfMemoryError thread death if nothing else is available, but a better strategy for an admin to handle an OutOfMemoryError is to start JVM with -XX:OnOutOfMemoryError flag with a script that shuts down (and restarts) Tomcat.
Comment 1 Konstantin Kolinko 2014-07-15 12:33:24 UTC
Created attachment 31813 [details]

First version of a patch implementing this feature.
The patch is for current trunk (at 1610400).
Comment 2 Mark Thomas 2014-07-15 16:48:43 UTC
-1 to adding this feature.

If there is a case where an exception triggers the stopping if this thread when it is safe for the thread to be restarted then the fix is to ensure that the thread is not stopped in the first place.
Comment 3 Konstantin Kolinko 2014-07-17 22:55:24 UTC
Created attachment 31827 [details]

Second version.
It just adds logging and sets "thread = null;" to allow restarting the thread.
Comment 4 Konstantin Kolinko 2014-07-17 23:15:17 UTC
Tested patch v2. The message looks good.

Committed in trunk and tc7.0.x. It will be in 8.0.11 and 7.0.55.
( r1611506 r1611509 )
Comment 5 Mark Thomas 2019-08-09 17:28:28 UTC
Looking at the code for 9.0.x, 8.5.x and 7.0.x this looks to be complete and has been for a while.