Skip to content

Commit ad40676

Browse files
ahus1vietj
authored andcommitted
Restore handling of headers after goaway received
This re-enables a graceful shutdown that was broken after ff78924 Closes #5693 (cherry picked from commit 9a399e2)
1 parent d16a032 commit ad40676

File tree

2 files changed

+52
-10
lines changed

2 files changed

+52
-10
lines changed

vertx-core/src/main/java/io/vertx/core/http/impl/Http2ConnectionBase.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,20 +203,16 @@ public void onPriorityRead(ChannelHandlerContext ctx, int streamId, int streamDe
203203

204204
@Override
205205
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endOfStream) throws Http2Exception {
206-
if (goAwayStatus == null || endOfStream) {
207-
StreamPriority streamPriority = new StreamPriority()
208-
.setDependency(streamDependency)
209-
.setWeight(weight)
210-
.setExclusive(exclusive);
211-
onHeadersRead(streamId, headers, streamPriority, endOfStream);
212-
}
206+
StreamPriority streamPriority = new StreamPriority()
207+
.setDependency(streamDependency)
208+
.setWeight(weight)
209+
.setExclusive(exclusive);
210+
onHeadersRead(streamId, headers, streamPriority, endOfStream);
213211
}
214212

215213
@Override
216214
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding, boolean endOfStream) throws Http2Exception {
217-
if (goAwayStatus == null || endOfStream) {
218-
onHeadersRead(streamId, headers, null, endOfStream);
219-
}
215+
onHeadersRead(streamId, headers, null, endOfStream);
220216
}
221217

222218
protected abstract void onHeadersRead(int streamId, Http2Headers headers, StreamPriority streamPriority, boolean endOfStream);

vertx-core/src/test/java/io/vertx/tests/http/Http2ClientTest.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,52 @@ public void testServerShutdownConnection() throws Exception {
10691069
await();
10701070
}
10711071

1072+
@Test
1073+
public void testServerGracefulShutdownBeforeHeaderSent() throws Exception {
1074+
server.requestHandler(req -> {
1075+
req.connection().shutdown();
1076+
req.response().end("OK");
1077+
});
1078+
startServer(testAddress);
1079+
1080+
client.request(requestOptions).compose(req -> req
1081+
.send()
1082+
.expecting(HttpResponseExpectation.SC_OK)
1083+
.compose(HttpClientResponse::end))
1084+
.andThen(resp -> {
1085+
if (resp.succeeded()) {
1086+
testComplete();
1087+
} else {
1088+
fail(resp.cause());
1089+
}
1090+
});
1091+
1092+
await();
1093+
}
1094+
1095+
@Test
1096+
public void testGoAwayErrorBeforeHeaderSent() throws Exception {
1097+
server.requestHandler(req -> {
1098+
req.connection().goAway(100);
1099+
req.response().end("OK");
1100+
});
1101+
startServer(testAddress);
1102+
1103+
client.request(requestOptions).compose(req -> req
1104+
.send()
1105+
.expecting(HttpResponseExpectation.SC_OK)
1106+
.compose(HttpClientResponse::end))
1107+
.andThen(resp -> {
1108+
if (resp.succeeded()) {
1109+
testComplete();
1110+
} else {
1111+
fail(resp.cause());
1112+
}
1113+
});
1114+
1115+
await();
1116+
}
1117+
10721118
@Test
10731119
public void testReceivingGoAwayDiscardsTheConnection() throws Exception {
10741120
AtomicInteger reqCount = new AtomicInteger();

0 commit comments

Comments
 (0)