Fix NPE in Http2ConnectionHandler.onHttpServerUpgrade

Motivation:

Performing a server upgrade with a new initial flow control window will cause an NPE in the DefaultHttp2RemoteFlowController. This is due to the fact that the monitor does not check whether or not the channel is writable.

Modifications:

Added a check for channel writability before calling `writePendingBytes`. Also fixed a unit test that was supposed to be testing this :).

Result:

Fixes #5301
This commit is contained in:
nmittler 2016-05-25 08:58:40 -07:00
parent b3c56d5f69
commit 79a06eaede
2 changed files with 6 additions and 1 deletions

View File

@ -641,7 +641,7 @@ public class DefaultHttp2RemoteFlowController implements Http2RemoteFlowControll
}
});
if (delta > 0) {
if (delta > 0 && isChannelWritable()) {
// The window size increased, send any pending frames for all streams.
writePendingBytes();
}

View File

@ -45,7 +45,9 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import io.netty.handler.codec.http2.Http2FrameWriter.Configuration;
import io.netty.util.concurrent.EventExecutor;
import junit.framework.AssertionFailedError;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
@ -902,6 +904,9 @@ public abstract class DefaultHttp2RemoteFlowControllerTest {
// Re-initialize the controller so we can ensure the context hasn't been set yet.
initConnectionAndController();
// This should not throw.
controller.initialWindowSize(1024 * 100);
FakeFlowControlled dataA = new FakeFlowControlled(1);
final Http2Stream stream = stream(STREAM_A);