Skip to content

Weird websocket client behaviour with pooled allocator #4635

Closed

Description

@lexek

A few days ago I noticed that my websocket clients are being disconnected in weird way. I found that, when upgrade is complete, exception below is being thrown from HttpResponseDecoder and WebSocketClientProtocolHandler just closes connection on exception. And this happens only if i use pooled allocator for channels.

io.netty.handler.codec.DecoderException: io.netty.util.IllegalReferenceCountException: refCnt: 0
    at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:391)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:244)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)
    at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
    at java.lang.Thread.run(Thread.java:745)
Caused by: io.netty.util.IllegalReferenceCountException: refCnt: 0
    at io.netty.buffer.AbstractByteBuf.ensureAccessible(AbstractByteBuf.java:1190)
    at io.netty.buffer.AbstractByteBuf.checkReadableBytes0(AbstractByteBuf.java:1176)
    at io.netty.buffer.AbstractByteBuf.checkReadableBytes(AbstractByteBuf.java:1172)
    at io.netty.buffer.AbstractByteBuf.readBytes(AbstractByteBuf.java:672)
    at io.netty.handler.codec.http.HttpObjectDecoder.decode(HttpObjectDecoder.java:390)
    at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:360)
    ... 12 more

System info

Linux Atplaychannel 3.5.0-17-generic #28-Ubuntu SMP Tue Oct 9 19:31:23 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

Java version

java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)

This happens only when first websocket frame is being received in same packet as upgrade response.
Netty version is 4.0.33.Final and it looks like that previous versions don't have this issue.

Code that reproduces the issue https://gist.github.com/lexek/b61d0980f029f47b353b

Activity

  1. normanmaurer commented on Dec 29, 2015

    @normanmaurer
    Member

    @lexek will have a look

  2. self-assigned this
    on Dec 29, 2015
  3. normanmaurer commented on Dec 29, 2015

    @normanmaurer
    Member

    @lexek what websockets version ?

  4. lexek commented on Dec 29, 2015

    @lexek
    Author
  5. normanmaurer commented on Dec 29, 2015

    @normanmaurer
    Member

    @lexek so far not luck reproduce it with your code on linux and OS X :(

  6. lexek commented on Dec 29, 2015

    @lexek
    Author

    @normanmaurer is channel getting closed right with first websocket frame? I had to put logging handler before websocket handler to see the exception itself, because webscocket handler closes channel silently on any exception, sorry I din't mention that. Updated gist too.

  7. normanmaurer commented on Dec 29, 2015

    @normanmaurer
    Member

    @lexek was able to reproduce it one time now. I think I know what the issue is... let me try to write a unit test and a fix.

  8. added this to the 4.0.34.Final milestone on Dec 29, 2015
  9. added a commit that references this issue on Jan 4, 2016
  10. normanmaurer commented on Jan 4, 2016

    @normanmaurer
    Member

    @lexek please test #4651

  11. lexek commented on Jan 4, 2016

    @lexek
    Author

    @normanmaurer tested and looks like it is fixed

  12. normanmaurer commented on Jan 4, 2016

    @normanmaurer
    Member

    @lexek thanks for verify!

  13. added 2 commits that reference this issue on Jan 5, 2016
  14. normanmaurer commented on Jan 5, 2016

    @normanmaurer
    Member

    Fixed by #4651

  15. added 3 commits that reference this issue on Apr 14, 2016
  16. added 2 commits that reference this issue on Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions