Skip to content

Commit 37c4e28

Browse files
committed
When an error occurs during a streaming response, call HttpServerResponse.reset()
Fixes: quarkusio#50336
1 parent 5110dde commit 37c4e28

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

extensions/resteasy-reactive/rest-servlet/runtime/src/main/java/io/quarkus/resteasy/reactive/server/servlet/runtime/ServletRequestContext.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,4 +724,9 @@ public void handle(Void event) {
724724
});
725725
return this;
726726
}
727+
728+
@Override
729+
public void reset() {
730+
context.response().reset();
731+
}
727732
}

independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/PublisherResponseHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ protected void handleException(ResteasyReactiveRequestContext requestContext, Th
246246
// it will appear to be an SSE value, which is incorrect, so we should only log it and close the connection
247247
if (requestContext.serverResponse().headWritten()) {
248248
log.error("Exception in SSE server handling, impossible to send it to client", t);
249+
// HTTP chunked encoding sends an indeterminate number of chunks, but it has to end with an end chunk of zero size to indicate successful transmission.
250+
// reset() will cause this last chunk to not be sent, even though every other chunk was sent, and so clients can detect the error
251+
requestContext.serverResponse().reset();
249252
} else {
250253
// we can go through the abort chain
251254
requestContext.resume(t, true);

independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/spi/ServerHttpResponse.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,6 @@ public interface ServerHttpResponse extends StreamingResponse<ServerHttpResponse
5050
boolean isWriteQueueFull();
5151

5252
ServerHttpResponse addDrainHandler(Runnable onDrain);
53+
54+
void reset();
5355
}

independent-projects/resteasy-reactive/server/vertx/src/main/java/org/jboss/resteasy/reactive/server/vertx/VertxResteasyReactiveRequestContext.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,11 @@ public void handle(Void event) {
531531
return this;
532532
}
533533

534+
@Override
535+
public void reset() {
536+
response.reset();
537+
}
538+
534539
@Override
535540
public boolean isWriteQueueFull() {
536541
return response.writeQueueFull();

0 commit comments

Comments
 (0)