Skip to content

Commit

Permalink
BodyHandler implementation should only resume and set handlers when t…
Browse files Browse the repository at this point in the history
…he request is not ended
  • Loading branch information
vietj committed Mar 1, 2023
1 parent 3b7fcb7 commit e39a6cf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,14 @@ public void handle(RoutingContext context) {
}

final BHandler handler = new BHandler(context, isPreallocateBodyBuffer ? parsedContentLength : -1);
request
// resume the request (if paused)
.resume()
.handler(handler)
.endHandler(handler::end);
boolean ended = request.isEnded();
if (!ended) {
request
// resume the request (if paused)
.handler(handler)
.endHandler(handler::end)
.resume();
}
} else {
// on reroute we need to re-merge the form params if that was desired
if (mergeFormAttributes && request.isExpectMultipart()) {
Expand Down
19 changes: 16 additions & 3 deletions vertx-web/src/test/java/io/vertx/ext/web/RouterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3473,8 +3473,12 @@ public void testPausedConnection() {

router.route()
.handler((PlatformHandler) ctx -> {
ctx.request().pause();
ctx.vertx()
.setTimer(1L, t -> ctx.next());
.setTimer(1L, t -> {
ctx.request().resume();
ctx.next();
});
});

router.route("/")
Expand Down Expand Up @@ -3505,8 +3509,12 @@ public void testPausedConnection2() {

router.route()
.handler((PlatformHandler) ctx -> {
ctx.request().pause();
ctx.vertx()
.setTimer(1L, t -> ctx.next());
.setTimer(1L, t -> {
ctx.request().resume();
ctx.next();
});
});

// this variation shows that if there's only web handlers, it still works
Expand All @@ -3523,6 +3531,7 @@ public void testPausedConnection2() {
// 8192 * 8 fills the HTTP server request pending queue
// => pauses the HttpConnection (see Http1xServerRequest#handleContent(Buffer) that calls Http1xServerConnection#doPause())
req.send(TestUtils.randomBuffer(8192 * 8)).onComplete(onSuccess(resp -> {
assertEquals(404, resp.statusCode());
complete();
}));
}));
Expand All @@ -3536,8 +3545,12 @@ public void testPausedConnection3() {

router.route()
.handler((PlatformHandler) ctx -> {
ctx.request().pause();
ctx.vertx()
.setTimer(1L, t -> ctx.next());
.setTimer(1L, t -> {
ctx.request().resume();
ctx.next();
});
});

// ensure that even if there are callbacks waiting for the request end event, the resume did happen correctly
Expand Down

0 comments on commit e39a6cf

Please sign in to comment.