Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process not terminated on OOM error #1258

Closed
bojanv55 opened this issue Oct 16, 2020 · 13 comments · Fixed by #1259 or #1260
Closed

Process not terminated on OOM error #1258

bojanv55 opened this issue Oct 16, 2020 · 13 comments · Fixed by #1259 or #1260

Comments

@bojanv55
Copy link

How come this happened - that is - is this expected behavior? My application was not terminated and started working pretty strange - seems like it could not recover from this java.lang.OutOfMemoryError - but still, spring did not terminate the APP but it continue to run.

2020-10-16 16:57:46 (ERROR): ForgivingExceptionHandler Consumer SimpleConsumer [queue=my.partitioned.32.8.user, consumerTag=phoenix.lcoo.clientodds.7b892e20-480a-420a-
java.lang.OutOfMemoryError: Java heap space
        at java.base/java.util.Arrays.copyOf(Arrays.java:3745)
        at java.base/java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:120)
        at java.base/java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:95)
        at java.base/java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:156)
        at org.springframework.util.StreamUtils.copy(StreamUtils.java:143)
        at org.springframework.util.FileCopyUtils.copy(FileCopyUtils.java:110)
        at org.springframework.amqp.support.postprocessor.AbstractDecompressingPostProcessor.postProcessMessage(AbstractDecompressingPostProcessor.java:91)
        at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:1423)
        at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1400)
        at org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer$SimpleConsumer.callExecuteListener(DirectMessageListenerContainer.java:1036)
        at org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer$SimpleConsumer.handleDelivery(DirectMessageListenerContainer.java:996)
        at com.rabbitmq.client.impl.ConsumerDispatcher$5.run(ConsumerDispatcher.java:149)
        at com.rabbitmq.client.impl.ConsumerWorkService$WorkPoolRunnable.run(ConsumerWorkService.java:104)
        at com.codahale.metrics.InstrumentedExecutorService$InstrumentedRunnable.run(InstrumentedExecutorService.java:181)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:834)
2020-10-16 16:57:46 (ERROR): CachingConnectionFactory Channel shutdown: connection error
@garyrussell
Copy link
Contributor

It's not clear what you expect the framework to do in this case.

@bojanv55
Copy link
Author

I guess it cannot recover from this exception? I would just expect that my app exits. Is this something that is missing from my (mis)configuration of spring framework or?

@garyrussell
Copy link
Contributor

OOM errors are hard to deal with; generally the JVM needs to be restarted; with the SimpleMessageListenerContainer we generally create and send a listener failed event if some unexpected exception occurs; with the Direct container, this is run on the client thread; I suppose we could add a try/catch and publish the event (then your event listener code could decide what to do). The problem with OOM errors, though, is that it might prevent us from creating the event in the first place.

@bojanv55
Copy link
Author

This is from javadoc:

public class Error
extends Throwable
An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions. 

The problem I had is that I did not know that my application was in some partially working state, since It did not stop, but it did not work either how it should.

garyrussell added a commit to garyrussell/spring-amqp that referenced this issue Oct 20, 2020
garyrussell added a commit to garyrussell/spring-amqp that referenced this issue Oct 20, 2020
artembilan pushed a commit that referenced this issue Oct 20, 2020
Resolves #1258 (comment)

**I will backport to 2.2.x with a no-op default**
garyrussell added a commit that referenced this issue Oct 20, 2020
Resolves #1258 (comment)

**Backported to 2.2.x with a no-op default**
@bojanv55
Copy link
Author

Thanks. So by default (I do not need to configure anything?) - Direct and Simple listeners will exit the app on OOM?

@bojanv55
Copy link
Author

btw. this fixes my problem, so thanks for that, but shouldn't you implement handler for all Error cases? Basically to use java.lang.Error in catching logic. All these seem pretty serious conditions AnnotationFormatError, AssertionError, AWTError, CoderMalfunctionError, FactoryConfigurationError, FactoryConfigurationError, IOError, LinkageError, ServiceConfigurationError, ThreadDeath, TransformerFactoryConfigurationError, VirtualMachineError.

@garyrussell
Copy link
Contributor

So by default (I do not need to configure anything?)

Correct in the upcoming 2.3 release; with the 2.2.12 backport, the default behavior is do nothing (backwards compatibility); you have to set your own OOMHandler.

I suppose we could open it up to all errors, but, TBH, I don't think I have ever seen any of those errors in over 20 years working with Java.

@artembilan WDYT?

@artembilan
Copy link
Member

I don't think that we need care about those errors at the moment.
Let it be for a while!
We always can come back and extend when more and more requests will come.

@bojanv55
Copy link
Author

I just pasted those from javadocs, but I guess there are other common errors like - StackOverflowError, and instead then hardcoding all possible children, I guess easiest would be to just match all java.lang.Error errors.

@garyrussell
Copy link
Contributor

Stack overflow is not fatal; you can recover from it (unlike OOM). It would be wrong to kill the JVM.

@bojanv55
Copy link
Author

I guess this SO post has a good explanation about that: https://stackoverflow.com/a/52115695/4882336

@garyrussell
Copy link
Contributor

OK; convinced...

@garyrussell garyrussell reopened this Oct 22, 2020
garyrussell added a commit to garyrussell/spring-amqp that referenced this issue Oct 22, 2020
Resolves spring-projects#1258

Call the handler for all `Error`s on container threads.

**I will do the cherry-pick; there will be conflicts**
artembilan pushed a commit that referenced this issue Oct 22, 2020
Resolves #1258

Call the handler for all `Error`s on container threads.

**I will do the cherry-pick; there will be conflicts**
garyrussell added a commit that referenced this issue Oct 22, 2020
Resolves #1258

Call the handler for all `Error`s on container threads.

**I will do the cherry-pick; there will be conflicts**
garyrussell added a commit that referenced this issue Oct 22, 2020
@bojanv55
Copy link
Author

Thanx. Seems like more robust solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment