spring-cloud / spring-cloud/spring-cloud-gateway

IllegalReferenceCountException while reading the data from ByteBuf

Open
#3,460 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feedback-provided
Dominant language
Java
Stars
4.9k
Forks
3.5k
Avg merge
20h 57m
Merged PRs (30d)
8

Description

Bug Description

We have a Spring Cloud Gateway Application which uses Netty as a server to process request/response. We see a spike of IllegalReferenceCountException happening on a particular TCP connection, not on any other Connections. Traffic on other connection work absolutely fine.

Below is the complete stack trace:

io.netty.util.IllegalReferenceCountException: refCnt: 0 errorCause: refCnt: 0 extended errorStackTrace: io.netty.buffer.AbstractByteBuf.ensureAccessible(AbstractByteBuf.java:1454),io.netty.buffer.AbstractByteBuf.checkNewCapacity(AbstractByteBuf.java:1432),io.netty.buffer.PooledByteBuf.capacity(PooledByteBuf.java:105),io.netty.buffer.AbstractByteBuf.ensureWritable0(AbstractByteBuf.java:305),io.netty.buffer.AbstractByteBuf.ensureWritable(AbstractByteBuf.java:280),io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1103),io.netty.handler.codec.ByteToMessageDecoder$1.cumulate(ByteToMessageDecoder.java:105),io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:288),io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444),io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420), errorStackTrace: io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:294),io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444),io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420),io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412),io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93),ocpm.cne.gateway.util.ConnectionCountHandler.channelRead(ConnectionCountHandler.java:60),io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444),io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420),io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412),io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)

We would some guidance to understand what could be the reason that it only happens on one connection , while requests on other connections seems to work fine.

Netty version

4.1.109.Final

JVM version (e.g. java -version)

Java 17

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The report identifies Netty entry points including ByteToMessageDecoder.channelRead, AbstractByteBuf.ensureAccessible, and the application's ConnectionCountHandler.channelRead, but names no repository file or test. Start by tracing buffer ownership through those stack frames and obtain a reproducible case for the affected connection; done requires identifying a confirmed cause and a test or diagnostic that distinguishes it from normal connections.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
Domain
backend, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.