Bug 58004 - Possible memory leak on ClientAbortException in Ajp
Possible memory leak on ClientAbortException in Ajp
Status: RESOLVED FIXED
Product: Tomcat 8
Classification: Unclassified
Component: Connectors
8.0.23
PC Linux
: P2 normal (vote)
: ----
Assigned To: Tomcat Developers Mailing List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2015-06-05 09:34 UTC by Bo Madsen
Modified: 2015-08-31 05:51 UTC (History)
1 user (show)



Attachments
Example maven web application (23.81 KB, application/gzip)
2015-06-05 09:34 UTC, Bo Madsen
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bo Madsen 2015-06-05 09:34:38 UTC
Created attachment 32795 [details]
Example maven web application

When a client drops the connection during a request, a ClientAbortException is thrown. If the web application caches this, and then tries to write to the request outputstream it seems that a memory leak occurs.
I think it is a fairly general scenario where an exception is thrown while serving the request, and then the application tries to write an error response back to the client.

Looking at heap dumps it seems like the bufferedWrites property in AjpNioProcessor grows each time it happens.

I have attached a small web application that shows this issue. The culprit is BigStupidFileServlet that in line 36 writes to the response after having gotten an exception. To execute the sample do:
1) Deploy the web application to a Tomcat, or execute tomcat.example.Main to use the embedded tomcat, and expose it through ajp
2) Start an Apache HTTPD and point it to the Tomcat's ajp port
3) Execute tomcat.example.Breaker with the url of the apache, e.g.: mvn exec:java -Dexec.mainClass="tomcat.example.Breaker"  -Dexec.args="http://localhost:8080/tomcat-example/files/test.bin"
4) Observe that the Tomcat server will run out of memory quickly (on my machine around 6k requests, but it ofcause depends on heap size)
If you run the breaker on a http connector, it will continue running without OOM exceptions.
Comment 1 Remy Maucherat 2015-06-12 15:52:02 UTC
Buffering data in blocking mode seems wrong, it will be fixed in 8.0.24. However, it is really wrong to catch an IOE and expect to write some data ...
Comment 2 Anton Kagan 2015-08-31 05:51:42 UTC
We upgraded to 8.0.24 and still experience high memory usage with APR connector when client downloads a large file.
I can provide heap dumps if needed.