Skip to content

Commit 66783a8

Browse files
MartijnVisserbalassai
authored andcommitted
[FLINK-34644][runtime] Fix race condition in RestServerEndpoint shutdown (#27708)
* [FLINK-34644][runtime] Fix race condition in RestServerEndpoint shutdown causing flaky test Change thenAccept to thenCompose in AbstractRestHandler.respondToRequest() so that the returned future only completes after the HTTP response is fully flushed to the network. Previously, the future returned by HandlerUtils.sendResponse() was silently discarded, allowing InFlightRequestTracker.deregisterRequest() to fire before the response write completed. Under load this let shutDownInternal() tear down the Netty event loops while response bytes were still in flight, causing ConnectionClosedException on the client side. * [FLINK-34644][sql-gateway] Apply same thenAccept to thenCompose fix in AbstractSqlGatewayRestHandler Apply the same fix as AbstractRestHandler: change thenAccept to thenCompose in respondToRequest() so the returned future only completes after the HTTP response is fully flushed. This prevents the same race condition where in-flight request deregistration could fire before the response write completes.
1 parent cd0d323 commit 66783a8

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

flink-runtime/src/main/java/org/apache/flink/runtime/rest/handler/AbstractRestHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected CompletableFuture<Void> respondToRequest(
8585
response = FutureUtils.completedExceptionally(e);
8686
}
8787

88-
return response.thenAccept(
88+
return response.thenCompose(
8989
resp ->
9090
HandlerUtils.sendResponse(
9191
ctx,

flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/rest/handler/AbstractSqlGatewayRestHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ protected CompletableFuture<Void> respondToRequest(
8888
response = FutureUtils.completedExceptionally(e);
8989
}
9090

91-
return response.thenAccept(
91+
return response.thenCompose(
9292
resp ->
9393
HandlerUtils.sendResponse(
9494
ctx,

0 commit comments

Comments
 (0)