Skip to content

Commit

Permalink
fix: handle client disconnection in v3 compat mode of jupiter engine
Browse files Browse the repository at this point in the history
  • Loading branch information
gaetanmaisse committed May 30, 2023
1 parent 2b6763f commit 04fec38
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Expand Up @@ -257,7 +257,7 @@ private Handler<io.gravitee.gateway.api.ExecutionContext> endRequestHandler(
if (context.response().ended()) {
emitter.onComplete();
} else {
httpServerRequest.response().rxEnd().subscribe(emitter::onComplete, emitter::onError);
httpServerRequest.response().rxEnd().subscribe(emitter::onComplete, emitter::tryOnError);
}
};
}
Expand Down
Expand Up @@ -39,6 +39,7 @@
import io.gravitee.gateway.report.ReporterService;
import io.reactivex.rxjava3.core.Completable;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.observers.TestObserver;
import io.vertx.core.Future;
import io.vertx.core.Vertx;
Expand Down Expand Up @@ -321,6 +322,35 @@ void shouldEndResponseWhenNotAlreadyEndedByV3Handler() {
obs.assertResult();
}

@Test
void shouldEndResponseWhenClientConnexionIsClosed() {
final ReactorHandler apiReactor = mock(ReactorHandler.class);

this.prepareV3Mock(handlerEntrypoint, apiReactor);
when(gatewayConfiguration.tenant()).thenReturn(Optional.of("TENANT"));
when(gatewayConfiguration.zone()).thenReturn(Optional.of("ZONE"));
when(response.ended()).thenReturn(false);
when(rxResponse.rxEnd()).thenReturn(Completable.error(new RuntimeException()));

doAnswer(i -> {
final ExecutionContext ctx = i.getArgument(0, ExecutionContext.class);

assertEquals("TENANT", ctx.request().metrics().getTenant());
assertEquals("ZONE", ctx.request().metrics().getZone());
simulateEndHandlerCall(i);
return null;
})
.when(apiReactor)
.handle(any(ExecutionContext.class), any(Handler.class));

cut
.dispatch(rxRequest)
// Simulate when the client is ending the connection before the gateway got a response from the endpoint
.doOnSubscribe(Disposable::dispose)
.test()
.assertNoErrors();
}

@Test
void shouldPropagateErrorWhenExceptionWithV3Request() {
final ReactorHandler apiReactor = mock(ReactorHandler.class);
Expand Down

0 comments on commit 04fec38

Please sign in to comment.