GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — HTTP2: Ensure preface is flushed in all cases (#16407) · netty/netty@566768e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-http2/src
    • main/java/io/netty/handler/codec/http2
      • Http2ConnectionHandler.java
    • test/java/io/netty/handler/codec/http2
      • Http2ConnectionHandlerTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-http2/src/main/java/io/netty/handler/codec/http2/Http2ConnectionHandler.java‎

Copy file name to clipboardExpand all lines: codec-http2/src/main/java/io/netty/handler/codec/http2/Http2ConnectionHandler.java
+14-12Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,6 @@ public void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) thro
260260
public void channelActive(ChannelHandlerContext ctx) throws Exception {
261261
// The channel just became active - send the connection preface to the remote endpoint.
262262
sendPreface(ctx);
263-
264-
if (flushPreface) {
265-
// As we don't know if any channelReadComplete() events will be triggered at all we need to ensure we
266-
// also flush. Otherwise the remote peer might never see the preface / settings frame.
267-
// See https://github.com/netty/netty/issues/12089
268-
ctx.flush();
269-
}
270263
}
271264

272265
@Override
@@ -384,11 +377,20 @@ private void sendPreface(ChannelHandlerContext ctx) throws Exception {
384377
encoder.writeSettings(ctx, initialSettings, ctx.newPromise()).addListener(
385378
ChannelFutureListener.CLOSE_ON_FAILURE);
386379

387-
if (isClient) {
388-
// If this handler is extended by the user and we directly fire the userEvent from this context then
389-
// the user will not see the event. We should fire the event starting with this handler so this class
390-
// (and extending classes) have a chance to process the event.
391-
userEventTriggered(ctx, Http2ConnectionPrefaceAndSettingsFrameWrittenEvent.INSTANCE);
380+
try {
381+
if (isClient) {
382+
// If this handler is extended by the user and we directly fire the userEvent from this context then
383+
// the user will not see the event. We should fire the event starting with this handler so this
384+
// class (and extending classes) have a chance to process the event.
385+
userEventTriggered(ctx, Http2ConnectionPrefaceAndSettingsFrameWrittenEvent.INSTANCE);
386+
}
387+
} finally {
388+
if (flushPreface) {
389+
// As we don't know if any channelReadComplete() events will be triggered at all we need to ensure
390+
// we also flush. Otherwise the remote peer might never see the preface / settings frame.
391+
// See https://github.com/netty/netty/issues/12089
392+
ctx.flush();
393+
}
392394
}
393395
}
394396
}
Collapse file

‎codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ConnectionHandlerTest.java‎

Copy file name to clipboardExpand all lines: codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ConnectionHandlerTest.java
+24-1Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,19 +306,41 @@ public void clientShouldSendClientPrefaceStringWhenActive() throws Exception {
306306
when(connection.isServer()).thenReturn(false);
307307
when(channel.isActive()).thenReturn(false);
308308
handler = newHandler();
309+
verify(ctx, never()).flush();
309310
when(channel.isActive()).thenReturn(true);
310311
handler.channelActive(ctx);
311312
verify(ctx).write(eq(connectionPrefaceBuf()));
313+
verify(ctx).flush();
312314
}
313315

314316
@Test
315317
public void serverShouldNotSendClientPrefaceStringWhenActive() throws Exception {
316318
when(connection.isServer()).thenReturn(true);
317319
when(channel.isActive()).thenReturn(false);
318320
handler = newHandler();
321+
verify(ctx, never()).flush();
319322
when(channel.isActive()).thenReturn(true);
320323
handler.channelActive(ctx);
321324
verify(ctx, never()).write(eq(connectionPrefaceBuf()));
325+
verify(ctx).flush();
326+
}
327+
328+
@Test
329+
public void clientShouldSendClientPrefaceStringWhenAddedAfterActive() throws Exception {
330+
when(connection.isServer()).thenReturn(false);
331+
when(channel.isActive()).thenReturn(true);
332+
handler = newHandler();
333+
verify(ctx).write(eq(connectionPrefaceBuf()));
334+
verify(ctx).flush();
335+
}
336+
337+
@Test
338+
public void serverShouldNotSendClientPrefaceStringWhenAddedAfterActive() throws Exception {
339+
when(connection.isServer()).thenReturn(true);
340+
when(channel.isActive()).thenReturn(true);
341+
handler = newHandler();
342+
verify(ctx, never()).write(eq(connectionPrefaceBuf()));
343+
verify(ctx).flush();
322344
}
323345

324346
@Test
@@ -733,7 +755,8 @@ public void canCloseStreamWithVoidPromise() throws Exception {
733755

734756
@Test
735757
public void channelReadCompleteTriggersFlush() throws Exception {
736-
handler = newHandler();
758+
// Create the handler in a way that it will flush the preface by itself
759+
handler = newHandler(false);
737760
handler.channelReadComplete(ctx);
738761
verify(ctx, times(1)).flush();
739762
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.