Race condition (LastHttpContent vs ChannelInactive)

28 views
Skip to first unread message

Ming

unread,
Jan 19, 2017, 5:03:10 PM1/19/17
to Netty discussions
Hi,

I recently got a race condition issue within netty. I am writing a client library, and in my implementation of "SimpleChannelInboundHandler", I have channelRead0() and channelInactive().

My client communicates with a server. The server will close channel if it feels something wrong, and what the server does is: 1) send 400 response to the client; 2) close the channel.

However, on the client side, there is a rare chance that channelInactive gets called before channelRead0 for the last http content. This happens rarely, only when the network is extremely good. So my question is: 1) is this expected from Netty? 2) how to ensure that channelInactive gets called after the last http content is processed?

Thanks,
Ming


Code snippet

@Override
  public void channelInactive(ChannelHandlerContext ctx) throws Exception {
    // abort request
  }


@Override
  protected void channelRead0(ChannelHandlerContext ctx, Object msg) {
    // ...
    if (msg instanceof HttpContent) {
      // ...
      if (msg instanceof LastHttpContent) {
        // complete request
      }
    }
  }





Norman Maurer

unread,
Jan 20, 2017, 10:11:41 AM1/20/17
to ne...@googlegroups.com
This should never happen. Please open an issue with a reproducer.


--
You received this message because you are subscribed to the Google Groups "Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netty+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netty/2a9ef589-08d8-432c-8066-1ef10d3a94a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages