Skip to content

Commit

Permalink
Fix voidPromise in Http2FrameCodec.writeHeadersFrame (#13958)
Browse files Browse the repository at this point in the history
Motivation:

Writing a Http2HeadersFrame on a new stream with a void promise would
throw an IllegalStateException.

Modification:

Unvoid the promise in the code that requires adding a listener.

Result:

No IllegalStateException.
  • Loading branch information
yawkat committed Apr 9, 2024
1 parent a38a85c commit 33ed825
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,14 @@ private void writeGoAwayFrame(ChannelHandlerContext ctx, Http2GoAwayFrame frame,
}

private void writeHeadersFrame(final ChannelHandlerContext ctx, Http2HeadersFrame headersFrame,
final ChannelPromise promise) {
ChannelPromise promise) {

if (isStreamIdValid(headersFrame.stream().id())) {
encoder().writeHeaders(ctx, headersFrame.stream().id(), headersFrame.headers(), headersFrame.padding(),
headersFrame.isEndStream(), promise);
} else if (initializeNewStream(ctx, (DefaultHttp2FrameStream) headersFrame.stream(), promise)) {
promise = promise.unvoid();

final int streamId = headersFrame.stream().id();

encoder().writeHeaders(ctx, streamId, headersFrame.headers(), headersFrame.padding(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,13 @@ public void operationComplete(ChannelFuture future) throws Exception {
assertTrue(listenerExecuted.get());
}

@Test
public void writeHeadersVoidPromise() {
final Http2FrameStream stream = frameCodec.newStream();
channel.writeAndFlush(new DefaultHttp2HeadersFrame(new DefaultHttp2Headers()).stream(stream),
channel.voidPromise());
}

@Test
public void upgradeEventNoRefCntError() throws Exception {
frameInboundWriter.writeInboundHeaders(Http2CodecUtil.HTTP_UPGRADE_STREAM_ID, request, 31, false);
Expand Down

0 comments on commit 33ed825

Please sign in to comment.