Add null-check to Htt2FrameCodec#consumeBytes. (#7899)
Motivation: Streams can be deregistered so we can't assume their existence in the stream map. Modifications: Add a null-check in case a stream has been deregistered. Result: Fixes #7898.
This commit is contained in:
parent
0261e00662
commit
bd800fa7e7
@ -315,8 +315,9 @@ public class Http2FrameCodec extends Http2ConnectionHandler {
|
|||||||
|
|
||||||
final boolean consumeBytes(int streamId, int bytes) throws Http2Exception {
|
final boolean consumeBytes(int streamId, int bytes) throws Http2Exception {
|
||||||
Http2Stream stream = connection().stream(streamId);
|
Http2Stream stream = connection().stream(streamId);
|
||||||
// upgraded requests are ineligible for stream control
|
// Upgraded requests are ineligible for stream control. We add the null check
|
||||||
if (streamId == Http2CodecUtil.HTTP_UPGRADE_STREAM_ID) {
|
// in case the stream has been deregistered.
|
||||||
|
if (stream != null && streamId == Http2CodecUtil.HTTP_UPGRADE_STREAM_ID) {
|
||||||
Boolean upgraded = stream.getProperty(upgradeKey);
|
Boolean upgraded = stream.getProperty(upgradeKey);
|
||||||
if (Boolean.TRUE.equals(upgraded)) {
|
if (Boolean.TRUE.equals(upgraded)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -209,6 +209,20 @@ public class Http2FrameCodecTest {
|
|||||||
assertTrue(channel.isActive());
|
assertTrue(channel.isActive());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void flowControlShouldBeResilientToMissingStreams() throws Http2Exception {
|
||||||
|
Http2Connection conn = new DefaultHttp2Connection(true);
|
||||||
|
Http2ConnectionEncoder enc = new DefaultHttp2ConnectionEncoder(conn, new DefaultHttp2FrameWriter());
|
||||||
|
Http2ConnectionDecoder dec = new DefaultHttp2ConnectionDecoder(conn, enc, new DefaultHttp2FrameReader());
|
||||||
|
Http2FrameCodec codec = new Http2FrameCodec(enc, dec, new Http2Settings());
|
||||||
|
EmbeddedChannel em = new EmbeddedChannel(codec);
|
||||||
|
|
||||||
|
// We call #consumeBytes on a stream id which has not been seen yet to emulate the case
|
||||||
|
// where a stream is deregistered which in reality can happen in response to a RST.
|
||||||
|
assertFalse(codec.consumeBytes(1, 1));
|
||||||
|
assertTrue(em.finishAndReleaseAll());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void entityRequestEntityResponse() throws Exception {
|
public void entityRequestEntityResponse() throws Exception {
|
||||||
frameListener.onHeadersRead(http2HandlerCtx, 1, request, 0, false);
|
frameListener.onHeadersRead(http2HandlerCtx, 1, request, 0, false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user