0

We have an servlet that uploads files from customers and stores them on our server. Every few weeks the servlet fails with the following error:

java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOf(Arrays.java:2882)
    at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:100)
    at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:390)
    at java.lang.StringBuffer.append(StringBuffer.java:224)
    at java.util.logging.SimpleFormatter.format(SimpleFormatter.java:74)
    at org.apache.juli.FileHandler.publish(FileHandler.java:129)
    at java.util.logging.Logger.log(Logger.java:458)
    at java.util.logging.Logger.doLog(Logger.java:480)
    at java.util.logging.Logger.logp(Logger.java:680)
    at org.apache.juli.logging.DirectJDKLog.log(DirectJDKLog.java:167)
    at org.apache.juli.logging.DirectJDKLog.error(DirectJDKLog.java:135)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:274)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
    at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
    at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:769)
    at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:698)
    at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:891)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
    at java.lang.Thread.run(Thread.java:619)

Tomcat is running with -Xmx256M. I'm not sure how to debug this memory leak - could it be something to do with the java.util.logger filling up?

2 Answers 2

1

There probably isn't a memory leak; my guess is that someone tries to write a huge log message. Check the log settings.

Also check how much memory Tomcat uses on the manager page and how much is free. Depending on your web app, 256MB might not be enough.

One last explanation could be a denial of service attack or an attempt to trigger a Java bug to hack your server.

Sign up to request clarification or add additional context in comments.

1 Comment

Looking at the apache logs I think it might have been a denial of service attack, not to do with tomcat.
1

You've probably got something that holds on to some object references and never lets go. It's not that the logger is filling up memory, but the logger probably runs most frequently and is therefore the first thing to notice if you do fill up your heap.

3 Comments

This is a possibility, but it could also be an abnormally large value being logged.
I have a static instance to an org.apache.Log4j.Logger. Could holiding an instance for the lifetime of the servlet cause an OutOfMemoryError?
@Tarski: unlikely. The problem does not appear to be with memory occupied by the Logger permanently. It's crashing when building a log message, which uses memory that is released quickly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.