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:
parent
e707a62a76
commit
6862ab76c0
@ -245,10 +245,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 {
|
||||
@ -268,9 +278,9 @@ public class Http2FrameCodec extends Http2ConnectionHandler {
|
||||
} finally {
|
||||
upgrade.release();
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
ctx.fireUserEventTriggered(evt);
|
||||
}
|
||||
super.userEventTriggered(ctx, evt);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user