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 — Auto-port 5.0: HTTP/2: Prevent reentrant flush on writability change … · netty/netty@03447d5

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
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public class Http2ConnectionHandler extends ByteToMessageDecoder implements Http
8080
private FutureListener<Void> closeListener;
8181
private BaseDecoder byteDecoder;
8282
private long gracefulShutdownTimeoutMillis;
83+
private boolean inFlush;
8384

8485
protected Http2ConnectionHandler(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder,
8586
Http2Settings initialSettings) {
@@ -190,6 +191,7 @@ public void onHttpServerUpgrade(Http2Settings settings) throws Http2Exception {
190191

191192
@Override
192193
public void flush(ChannelHandlerContext ctx) {
194+
inFlush = true;
193195
try {
194196
// Trigger pending writes in the remote flow controller.
195197
encoder.flowController().writePendingBytes();
@@ -198,6 +200,8 @@ public void flush(ChannelHandlerContext ctx) {
198200
onError(ctx, true, e);
199201
} catch (Throwable cause) {
200202
onError(ctx, true, connectionError(INTERNAL_ERROR, cause, "Error flushing"));
203+
} finally {
204+
inFlush = false;
201205
}
202206
}
203207

@@ -469,7 +473,7 @@ public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exceptio
469473
// Writability is expected to change while we are writing. We cannot allow this event to trigger reentering
470474
// the allocation and write loop. Reentering the event loop will lead to over or illegal allocation.
471475
try {
472-
if (ctx.channel().isWritable()) {
476+
if (ctx.channel().isWritable() && !inFlush) {
473477
flush(ctx);
474478
}
475479
encoder.flowController().channelWritabilityChanged();
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
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,26 @@ public void serverShouldNotSendClientPrefaceStringWhenAddedAfterActive() throws
313313
verify(ctx).flush();
314314
}
315315

316+
@Test
317+
public void channelWritabilityChangedShouldNotReenterFlush() throws Exception {
318+
when(channel.isActive()).thenReturn(false);
319+
when(channel.isWritable()).thenReturn(true);
320+
handler = newHandler();
321+
doAnswer(new Answer<Void>() {
322+
@Override
323+
public Void answer(InvocationOnMock invocation) throws Throwable {
324+
handler.channelWritabilityChanged(ctx);
325+
return null;
326+
}
327+
}).when(ctx).flush();
328+
329+
handler.flush(ctx);
330+
331+
verify(remoteFlow).writePendingBytes();
332+
verify(ctx).flush();
333+
verify(remoteFlow).channelWritabilityChanged();
334+
}
335+
316336
@Test
317337
public void serverReceivingInvalidClientPrefaceStringShouldHandleException() throws Exception {
318338
when(connection.isServer()).thenReturn(true);

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.