IllegalReferenceCountException with Netty 4.1.130.Final when using WSS/TLS

Author: mabiCreated Mar 4, 2026Updated Jul 8, 2026

When using Netty-socketio 2.0.14 that depends on Netty 4.1.130.Final, enabling WSS/TLS for SocketIO connections triggers a fatal buffer error:

ERROR com.corundumstudio.socketio.listener.DefaultExceptionListener - refCnt: 0
io.netty.util.IllegalReferenceCountException: refCnt: 0
	at io.netty.buffer.AbstractByteBuf.ensureAccessible(AbstractByteBuf.java:1454)
	at io.netty.buffer.PooledHeapByteBuf.array(PooledHeapByteBuf.java:231)
	at io.netty.buffer.CompositeByteBuf.array(CompositeByteBuf.java:793)
	at io.netty.buffer.ByteBufUtil.decodeString(ByteBufUtil.java:1360)
	at io.netty.buffer.AbstractByteBuf.toString(AbstractByteBuf.java:1246)
	at io.netty.buffer.AbstractByteBuf.toString(AbstractByteBuf.java:1241)
	at com.corundumstudio.socketio.handler.InPacketHandler.channelRead0(InPacketHandler.java:124)
	at com.corundumstudio.socketio.handler.InPacketHandler.channelRead0(InPacketHandler.java:37)

This does not occur when forcing earlier Netty versions (e.g. 4.1.115.Final). Plain WS/HTTP works fine. Likely caused by changes in buffer release management between Netty versions.

Repro: Use netty-socketio 2.0.14, verify that it is using Netty to 4.1.130.Final or later, enable WSS/TLS and connect with a SocketIO client.

For reference: Downgrading Netty resolves the issue.