Open Toseban opened 3 months ago
/cc @FroMage (resteasy-reactive), @stuartwdouglas (resteasy-reactive)
@franz1981 this will interest you
I will take a look later today but...
When returning an InputStream with a size larger than the configured -XX:MaxDirectMemorySize
The max direct memory size of Netty, if not configured, uses the one configured in the JVM args and the pooled allocator too has some limits of what is going to be pooled i.e. big buffers are not pooled but allocated and removed on the flight. So, in general, is a red flag to allocate beyond the configured direct memory capacity. If the allocated buffers are used from a Netty thread, there is no way to block it, so we can just keep on accumulate it and let Netty to provide some feedback that we are overallocating (suspending reading from vertx, at connection level), but that means that if the overallocating is happening from a different connection, we always risk to react too late and the only option is to close forcibly the connection while throwing an exception back to the user code. Wdyt @geoand ?
Just as an additional note, when we saw this happen in our application we did not have an explicit -XX:MaxDirectMemorySize
configured (it defaulted to 1GB in that scenario)
we did not have an explicit -XX:MaxDirectMemorySize configured
in that case by default Netty uses the max heap size (configured or implied) as max direct memory limit.
Describe the bug
When returning an
InputStream
with a size larger than the configured-XX:MaxDirectMemorySize
, there is anOutOfMemoryError
when the client does not consume the content fast enough.In
VertxOutputStream
the following code just sends all data to netty, which then buffers it in memory:Expected behavior
If a client is consuming data slowly, it should not be loaded into memory fully and no
OutOfMemoryError
should occurActual behavior
How to Reproduce?
Run the
QuarkusTest
in the attached example project with-XX:MaxDirectMemorySize=100m
quarkus-oom.zipOutput of
uname -a
orver
Microsoft Windows [Version 10.0.19045.4529]
Output of
java -version
openjdk version "21.0.1" 2023-10-17 OpenJDK Runtime Environment (build 21.0.1+12-29) OpenJDK 64-Bit Server VM (build 21.0.1+12-29, mixed mode, sharing)
Quarkus version or git rev
3.12.0
Build tool (ie. output of
mvnw --version
orgradlew --version
)Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae) Maven home: C:\Users\redacted\Java\apache-maven-3.9.6-bin\apache-maven-3.9.6 Java version: 21.0.1, vendor: Oracle Corporation, runtime: C:\Users\redacted.jdks\openjdk-21.0.1 Default locale: en_US, platform encoding: UTF-8 OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
Additional information
The issue occurs both on Windows and on Linux