Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,25 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable e) {

@Override
public void channelActive(ChannelHandlerContext ctx) {
ctx.read();
readIfNeeded(ctx);
}

@Override
public void channelReadComplete(ChannelHandlerContext ctx) {
ctx.read();
readIfNeeded(ctx);
}

/**
* Requests the next read only when the channel will not do it by itself: Netty's {@code HeadContext}
* calls {@code Channel#read()} once channelActive and channelReadComplete have been fired whenever
* autoRead is on, so reading here as well would just repeat the outbound traversal and doBeginRead.
* Same guard as {@code SslHandler#readIfNeeded}, which {@code Http2ConnectionHandler}
* inlines in {@code channelReadComplete0}.
*/
private static void readIfNeeded(ChannelHandlerContext ctx) {
if (!ctx.channel().config().isAutoRead()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right call checking this per event instead of caching it at channelActive. autoRead is a volatile field and a user handler can flip it mid connection, so a cached value would go wrong quietly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. autoRead is volatile and a user handler can flip it mid connection, so a value cached at channelActive would have been wrong in a way that produces a stalled connection rather than a failure.

ctx.read();
}
}

void finishUpdate(NettyResponseFuture<?> future, Channel channel, boolean close) {
Expand Down
Loading