-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Memory leak with Resteasy byte response? #20822
Comments
Any change you can attach a ready made project that reproduces this behavior? |
Sure, I added the zipped Maven project to the original post. |
I assume that the OOM happen when the service is under load, correct? |
From what I can see, this is not due to a memory leak, but do to file being large and too much memory being allocated when the concurrency is high enough. I also tried the same example using |
I can reproduce the same thing with smaller responses and no load on the system. So do you suggest that I try using quarkus-resteasy-reactive instead? |
I was not able to reproduce this without load.
Yes, please do and let us know how it goes. |
I think the "-w" part is important because it makes curl fail to read the response. With that I can reproduce the leak. I see the following curl output for the exact query (with
instead of for a normal curl that succeeds
And then on the quarkus side in the log for the first one there is:
|
I still could not reproduce the problem |
Did you also use curl to send the requests? And how many did you send? |
Strange. I tried the reproducer on Windows with Coretto 11 as well as Microsoft OpenJDK 17 runtimes. Curl was curl 7.55.1 (Windows) libcurl/7.55.1 WinSSL. I also tried it on Ubuntu 20.04 (WSL) with OpenJDK 14.0.1 and curl 7.68.0 (x86_64-pc-linux-gnu) libcurl/7.68.0. All had the same behavior. In my try right now on windows with Coretto 11 I started it using
and after 274 consecutive requests with curl from powershell for($num =1;$num -le 1000;$num++) { echo $num; curl -v --request GET http://localhost:8080/hello -w 'http_status: %{http_code}\n' -s } I got the messages as shown above and memory use climbed steadily to ~10GB before I started to get the OOM exception
I left it running for a few minutes after that without any new requests but memory use did not return to normal levels. |
The idea of this change is to make the allocation of buffers only happen when the previous write has been completed, as opposed to the previous behavior where all the buffers where allocated upfront and could never be deallocated if one of the writes caused an error Fixes: quarkusio#20822
#20907 takes care of the issue. |
Ensure that a large response does not cause OOM in RESTEasy Classic
Describe the bug
I implement a rest API that should return binary content.
After calling the service a bunch of times (depends on the response size), it runs out of memory and returns an OOM exception: "org.jboss.resteasy.spi.UnhandledException: java.lang.OutOfMemoryError: Direct buffer memory".
Expected behavior
I expect the used DirectBufferMemory to be freed at some point.
Actual behavior
The DirectBufferMemory is not released and therefore grows with each request.
Sending requests with curl (without doing anything with the response) leads to memory increase.
I investigated some heap dumps and it seems like netty.PoolChunk instances prevent the DirectByteBuffer objects from being removed.
How to Reproduce?
I reproduced the behavior with some small changes to the getting-started project's GreetingResource. It now produces "image/png" instead of "application/json" and basically loads a file and returns it as byte array. The code of the GreetingResource.java is the following:
After starting Quarkus dev mode on my local computer I can send approximately 300 curl requests (that do just fire and forget) until the service runs out of memory:
curl --request GET "http://localhost:8080/hello" -w 'http_status: %{http_code}\n' -s
Output of
uname -a
orver
No response
Output of
java -version
11.0.7
GraalVM version (if different from Java)
No response
Quarkus version or git rev
2.3.0
Build tool (ie. output of
mvnw --version
orgradlew --version
)Apache Maven 3.8.1
Additional information
Quarkus-getting-started.zip
The text was updated successfully, but these errors were encountered: