java.lang.OutOfMemoryError: Direct buffer memory when enabling logger debugging

Hi. This is my first post. I’m very new to Gatling.

I am trying to debug “j.i.IOException: Premature close” by turning on traces.
Anytime I enable http engine traces, I get an OOM stack trace (below) when starting up the simulation.
Has anyone encountered/resolved this problem? If so, please advise.

If it helps, I can include my .scala file. I’ll need to sanitize, but omitted it mainly for brevity.

This is the log line that I turn on in logback.xml

        <!-- uncomment and set to DEBUG to log all failing HTTP requests -->
        <!-- uncomment and set to TRACE to log all HTTP requests -->
        **<logger name="io.gatling.http.engine.response" level="TRACE" />**
14:43:06.751 [ERROR] i.g.h.c.i.HttpAppHandler - Fatal error
java.lang.OutOfMemoryError: Direct buffer memory
	at java.base/java.nio.Bits.reserveMemory(
	at java.base/java.nio.DirectByteBuffer.<init>(
	at java.base/java.nio.ByteBuffer.allocateDirect(
	at io.netty.buffer.PoolArena$DirectArena.allocateDirect(
	at io.netty.buffer.PoolArena$DirectArena.newChunk(
	at io.netty.buffer.PoolArena.allocateNormal(
	at io.netty.buffer.PoolArena.tcacheAllocateSmall(
	at io.netty.buffer.PoolArena.allocate(
	at io.netty.buffer.PoolArena.allocate(
	at io.netty.buffer.PooledByteBufAllocator.newDirectBuffer(
	at io.netty.buffer.AbstractByteBufAllocator.directBuffer(
	at io.netty.buffer.AbstractByteBufAllocator.directBuffer(
	at io.netty.handler.ssl.SslHandler.allocate(
	at io.netty.handler.ssl.SslHandler.unwrap(
	at io.netty.handler.ssl.SslHandler.decodeJdkCompatible(
	at io.netty.handler.ssl.SslHandler.decode(
	at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(
	at io.netty.handler.codec.ByteToMessageDecoder.callDecode(
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(
	at io.netty.util.concurrent.SingleThreadEventExecutor$
	at io.netty.util.internal.ThreadExecutorMap$
	at java.base/

Runtime info:

  • Ubuntu 22.04 LTS (8 dedicated CPU VM with 64GB ram)
  • openjdk version “11.0.19” 2023-04-18
    OpenJDK Runtime Environment (build 11.0.19+7-post-Ubuntu-0ubuntu122.04.1)
    OpenJDK 64-Bit Server VM (build 11.0.19+7-post-Ubuntu-0ubuntu122.04.1, mixed mode, sharing)

java opts (I’ve tried higher/lower, same outcome)
export JAVA_OPTS=‘-Xmx10240m’ (yes, 10Gb)

  • gatling-charts-highcharts-bundle-3.9.5

The issue is most likely the other way around: you’re allocating so much of the machine’s native memory for the heap that there’s no more room for the non-heap one.

So I changed the JAVA_OPTS down to 528m, and now its working. Thank you! I hope this post helps someone else.