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 4.1: HTTP/2: Prevent reentrant flush on writability change … · netty/netty@48c8075

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
@@ -79,6 +79,7 @@ public class Http2ConnectionHandler extends ByteToMessageDecoder implements Http
7979
private ChannelFutureListener closeListener;
8080
private BaseDecoder byteDecoder;
8181
private long gracefulShutdownTimeoutMillis;
82+
private boolean inFlush;
8283

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

190191
@Override
191192
public void flush(ChannelHandlerContext ctx) {
193+
inFlush = true;
192194
try {
193195
// Trigger pending writes in the remote flow controller.
194196
encoder.flowController().writePendingBytes();
@@ -197,6 +199,8 @@ public void flush(ChannelHandlerContext ctx) {
197199
onError(ctx, true, e);
198200
} catch (Throwable cause) {
199201
onError(ctx, true, connectionError(INTERNAL_ERROR, cause, "Error flushing"));
202+
} finally {
203+
inFlush = false;
200204
}
201205
}
202206

@@ -459,7 +463,7 @@ public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exceptio
459463
// Writability is expected to change while we are writing. We cannot allow this event to trigger reentering
460464
// the allocation and write loop. Reentering the event loop will lead to over or illegal allocation.
461465
try {
462-
if (ctx.channel().isWritable()) {
466+
if (ctx.channel().isWritable() && !inFlush) {
463467
flush(ctx);
464468
}
465469
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
@@ -343,6 +343,26 @@ public void serverShouldNotSendClientPrefaceStringWhenAddedAfterActive() throws
343343
verify(ctx).flush();
344344
}
345345

346+
@Test
347+
public void channelWritabilityChangedShouldNotReenterFlush() throws Exception {
348+
when(channel.isActive()).thenReturn(false);
349+
when(channel.isWritable()).thenReturn(true);
350+
handler = newHandler();
351+
doAnswer(new Answer<Void>() {
352+
@Override
353+
public Void answer(InvocationOnMock invocation) throws Throwable {
354+
handler.channelWritabilityChanged(ctx);
355+
return null;
356+
}
357+
}).when(ctx).flush();
358+
359+
handler.flush(ctx);
360+
361+
verify(remoteFlow).writePendingBytes();
362+
verify(ctx).flush();
363+
verify(remoteFlow).channelWritabilityChanged();
364+
}
365+
346366
@Test
347367
public void serverReceivingInvalidClientPrefaceStringShouldHandleException() throws Exception {
348368
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.