Delay Http2ConnectionPrefaceAndSettingsFrameWrittenEvent by one EventLoop tick when using the Http2FrameCodec (#9442)

Motivation:

We should delay the firing of the Http2ConnectionPrefaceAndSettingsFrameWrittenEvent by one EventLoop tick when using the Http2FrameCodec to ensure all handlers are added to the pipeline before the event is passed through it.

This is needed to workaround a race that could happen when the preface is send in handlerAdded(...) but a later handler wants to act on the event.

Modifications:

Offload firing of the event to the EventExecutor.

Result:

Fixes https://github.com/netty/netty/issues/9432.
This commit is contained in:
Norman Maurer 2019-08-13 10:50:18 +02:00
parent 2f0c00187a
commit 02408b306c

View File

@ -237,10 +237,20 @@ public class Http2FrameCodec extends Http2ConnectionHandler {
* HTTP/2 on stream 1 (the stream specifically reserved for cleartext HTTP upgrade).
*/
@Override
public final void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
public final void userEventTriggered(final ChannelHandlerContext ctx, final Object evt) throws Exception {
if (evt == Http2ConnectionPrefaceAndSettingsFrameWrittenEvent.INSTANCE) {
// The user event implies that we are on the client.
tryExpandConnectionFlowControlWindow(connection());
// We schedule this on the EventExecutor to allow to have any extra handlers added to the pipeline
// before we pass the event to the next handler. This is needed as the event may be called from within
// handlerAdded(...) which will be run before other handlers will be added to the pipeline.
ctx.executor().execute(new Runnable() {
@Override
public void run() {
ctx.fireUserEventTriggered(evt);
}
});
} else if (evt instanceof UpgradeEvent) {
UpgradeEvent upgrade = (UpgradeEvent) evt;
try {
@ -260,9 +270,9 @@ public class Http2FrameCodec extends Http2ConnectionHandler {
} finally {
upgrade.release();
}
return;
} else {
ctx.fireUserEventTriggered(evt);
}
super.userEventTriggered(ctx, evt);
}
/**