Bug 31426 - OutOfMemoryError: unable to create new native thread - and tomcat "hangs"
Summary: OutOfMemoryError: unable to create new native thread - and tomcat "hangs"
Status: RESOLVED WONTFIX
Alias: None
Product: Tomcat 5
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 5.0.19
Hardware: Other Linux
: P3 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
: 32262 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-09-26 16:48 UTC by Erik Pischel
Modified: 2006-04-07 06:07 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Erik Pischel 2004-09-26 16:48:02 UTC
we got this java.lang.OutOfMemoryError and we could not connect via HTTP to
tomcat any more. Although the main problem is the OutOfMemory Exception,
tomcat should handle this situation more gracefully.

Full error message is:
2004-09-23 23:59:59,135 ERROR [http8080-Processor265]
[org.apache.tomcat.util.threads.ThreadPool] Caught exception (java
.lang.OutOfMemoryError: unable to create new native thread) executing
org.apache.tomcat.util.net.TcpWorkerThread@36b4a7,
 terminating thread

It looks like the bug is in PoolTcpEndpoint, line 553 (in version 5.0.28) / line
547 (in version 5.0.19): in method "runIt", right after "acceptSocket"-call the
TcpWorkerThreads asks the connection pool of the enclosing TcpEndpoint to
execute itself (most importantly "acceptSocket") using
"endpoint.tp.runIt(this);" But when tp.runIt fails because it  got an
OutOfMemory exception up thread creation, the calling threads "dies" (in
ThreadPool.java, line 653 [version 5.0.19]) and there is no other thread calling
"acceptSocket" any more. 

Again, although the main issue here is the OutOfMemory exception (which probably
has to sth todo with # threads and lack of native memory etc.) tomcat should
handle that kind of "DoS" gracefully. It should not stop accepting HTTP requests
forever  (or any kind of requests since "TcpEndpoint" indicates it is not
limited to HTTP).

In my opinion, the current TcpWorkerThread should catch the exception, close the
current connection and return to "socketAccept"-mode.
Comment 1 Remy Maucherat 2004-09-27 06:32:00 UTC
You can patch your Tomcat to do that if you want to, but the main problem is
that the VM is not in a stable state once an OOM error occurs (and besides, the
VM will likely be spending all its time doing full GCs).
Finding the source of the OOM would be better for you, IMO.
Comment 2 Erik Pischel 2004-09-27 07:13:42 UTC
This has nothing to do with running out of heap. It is about running native
memory : every thread uses some native memory (mainly for stack trace). Even if
there is plenty of heap, native memory area might be to small to create a new
thread. So JVM should run stable if no other threads are created.
Comment 3 Erik Pischel 2004-09-27 07:18:03 UTC
ups, I meant "it is about running out of native memory" and native memory is
mainly used for thread stacks (not traces).

As for the proposed fix: on the other hand, the ThreadPool's contract might be
about not throwing an exception when failing to create a new thread but
tolerating this and queuing the runIt request for an existing thread to execute.
Comment 4 Yoav Shapira 2004-09-27 13:30:22 UTC
No, I disagree with your proposed fix.  The ability to work when your 
configuration is bad enough that you can't create a new thread is not something 
I want to even try to do.  Make sure your configuration (of the heap, of the 
stack size, and of the thread pool properties) works along with your hardware 
and operating system.
Comment 5 Rainer Jung 2004-11-16 10:43:07 UTC
*** Bug 32262 has been marked as a duplicate of this bug. ***
Comment 6 arnold goldberg 2006-04-07 02:08:03 UTC
This is obviously a problem with at least not logging the problem!
eBay gets OOM all the time in the application stack that are recoverable.

This behavior is unacceptable for an enterprise server.

Comment 7 arnold goldberg 2006-04-07 02:08:34 UTC
This is obviously a problem with at least not logging the problem!
eBay gets OOM all the time in the application stack that are recoverable.

This behavior is unacceptable for an enterprise server.

Comment 8 Leon Rosenberg 2006-04-07 10:50:04 UTC
We had the same issue (jdk1.5, tomcat 5.0.25) and it was solved by giving the vm
more PermGenSpace.