Skip to content
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

io.netty.util.IllegalReferenceCountException: refCnt: 0 in HttpSseClient example #335

Closed
hzariv opened this issue Feb 19, 2015 · 1 comment
Labels

Comments

@hzariv
Copy link

hzariv commented Feb 19, 2015

I wanted to print the data received from ServerSentEvent so I added the following line in HttpSseClient example to print out the data but after printing the first event content, I get IllegalReferenceCountException. There seems to be a race condition that data ByteBuf is released before my println.

for (ServerSentEvent event : eventIterable) {
System.out.println(event.contentAsString());
events.add(event);
}

New response received.

HTTP/1.1 200 OK
Transfer-Encoding: chunked
hello 0
Disconnected from the target VM, address: '127.0.0.1:49250', transport: 'socket'
Exception in thread "main" io.netty.util.IllegalReferenceCountException: refCnt: 0
at io.netty.buffer.AbstractByteBuf.ensureAccessible(AbstractByteBuf.java:1183)
at io.netty.buffer.AbstractByteBuf.checkIndex(AbstractByteBuf.java:1134)
at io.netty.buffer.PooledUnsafeDirectByteBuf.nioBuffer(PooledUnsafeDirectByteBuf.java:344)
at io.netty.buffer.AbstractByteBuf.toString(AbstractByteBuf.java:962)
at io.netty.buffer.AbstractByteBuf.toString(AbstractByteBuf.java:951)
at io.reactivex.netty.protocol.http.sse.ServerSentEvent.contentAsString(ServerSentEvent.java:128)
at io.reactivex.netty.examples.http.sse.HttpSseClient.readServerSideEvents(HttpSseClient.java:64)
at io.reactivex.netty.examples.http.sse.HttpSseClient.main(HttpSseClient.java:82)

@NiteshKant
Copy link
Member

@hzariv The problem here is that you are accessing the event content outside of the Observable chain. ServerSentEvent is a ByteBufHolder and gets released as soon as the onNext receiving the item returns ( more details on issue #264 ) .
If you want to access the content outside the chain, you should do a .retain() on the event in the chain and then release it once you have read.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants