Is the behaviour with ChannelHandlerContext.writeAndFlush when providing a ChannelPromise ok ?

77 views
Skip to first unread message

Jonathan

unread,
Oct 20, 2016, 10:23:20 AM10/20/16
to Netty discussions
Hi all ! 

I had kind of a bug today with :

 ChannelHandlerContext.writeAndFlush(Object, ChannelPromise).

Indeed I had some listeners on my promise, one of them being :

 promise.addListener(ChannelFutureListener.CLOSE);


The problem I encountered is that the promise is completed as soon as the WRITE is done, not after the FLUSH operation. So when it comes to the flush my channel is closed and I have a NPE...

My question is : Am I doing something wrong, or should the promise be completed AFTER the flush ? 

Besides, if I call 

 ChannelHandlerContext.write(Object, ChannelPromise).

it makes sense for the promise to be completed after the write, but with writeAndFlush I expected it to be completed and the flush.



Thanks before for your help, and keep the good work :) 

Jonathan

Chris Conroy

unread,
Oct 25, 2016, 3:06:51 PM10/25/16
to ne...@googlegroups.com

Interesting. Could you instead add a listener on the future returned from writeAndFlush?

Can you share the stacktrace of the NPE? close should be idempotent or at least throw a more specific exception.



Jonathan

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netty/ec9374c8-6616-43dc-9fb6-0ec540687e0c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jonathan

unread,
Oct 26, 2016, 3:55:14 AM10/26/16
to Netty discussions
Sure, here's the stack : 

Client pipeline caught an exception
java.lang.NullPointerException
        at io.netty.handler.codec.http2.DefaultHttp2RemoteFlowController.maxUsableChannelBytes(DefaultHttp2RemoteFlowController.java:238)
        at io.netty.handler.codec.http2.DefaultHttp2RemoteFlowController.writableBytes(DefaultHttp2RemoteFlowController.java:250)
        at io.netty.handler.codec.http2.DefaultHttp2RemoteFlowController.access$900(DefaultHttp2RemoteFlowController.java:43)
        at io.netty.handler.codec.http2.DefaultHttp2RemoteFlowController$WritabilityMonitor.writePendingBytes(DefaultHttp2RemoteFlowController.java:627)
        at io.netty.handler.codec.http2.DefaultHttp2RemoteFlowController.writePendingBytes(DefaultHttp2RemoteFlowController.java:255)
        at io.netty.handler.codec.http2.Http2ConnectionHandler.flush(Http2ConnectionHandler.java:161)
        at io.netty.channel.AbstractChannelHandlerContext.invokeFlush0(AbstractChannelHandlerContext.java:786)
        at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:812)
        at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:824)
        at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:804)

 Could you instead add a listener on the future returned from writeAndFlush?

Same problem because the future returned by writeAndFlush is actually the same as the promise you can use in the arguments.

Besides this behaviour could lead to tricky problems : if you add a listener on writeAndFlush and then the future is completed with succes but the flush() crash you won't be notified of this error (I mean you will be with the exceptionCaught, but not with the promise).


Thanks for answer :) 

Jonathan

Reply all
Reply to author
Forward
0 new messages