Skip to content

Commit

Permalink
Await completion in ServletHttpHandler.service for non-async containe…
Browse files Browse the repository at this point in the history
…rs (#438)

This patch only returns from service once the request has actually completed, and the response is guaranteed to be available. This fixes micronaut-projects/micronaut-starter#1734 . There may be adverse impact, I'm not sure.
  • Loading branch information
yawkat committed Apr 28, 2023
1 parent 6ae8b74 commit db4c573
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.function.Consumer;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -211,8 +213,22 @@ public void service(ServletExchange<REQ, RES> exchange) {
}));
});
} else {
CompletableFuture<?> termination = new CompletableFuture<>();
lc.handleNormal()
.onComplete((response, throwable) -> onComplete(exchange, req, response, throwable, requestTerminated));
.onComplete((response, throwable) -> {
try {
onComplete(exchange, req, response, throwable, requestTerminated);
} finally {
termination.complete(null);
}
});
try {
termination.get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (ExecutionException e) {
throw new AssertionError("we only call complete, shouldn't happen", e);
}
}
}

Expand Down

0 comments on commit db4c573

Please sign in to comment.