-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support cancelling in flight REST requests #41990
base: main
Are you sure you want to change the base?
Conversation
geoand
commented
Jul 19, 2024
•
edited
Loading
edited
- Resolves: Support connection reset on cancellation for generated REST clients #41971
Upon testing, I get the exception: stack trace``` Exception in thread "vert.x-eventloop-thread-0" kotlinx.coroutines.CompletionHandlerException: Exception in invokeOnCancellation handler for CancellableContinuation(DispatchedContinuation[VertxDispatcher@48ac8e1c, Continuation at org.example.CallCancelResource$cancel2$2$1.invokeSuspend(ExampleResource.kt:79)@117a641f]){Cancelled}@4711d835 at kotlinx.coroutines.CancellableContinuationImpl.callCancelHandler(CancellableContinuationImpl.kt:701) at kotlinx.coroutines.CancellableContinuationImpl.invokeOnCancellationImpl(CancellableContinuationImpl.kt:420) at kotlinx.coroutines.CancellableContinuationImpl.invokeOnCancellationInternal$kotlinx_coroutines_core(CancellableContinuationImpl.kt:395) at kotlinx.coroutines.CancellableContinuationKt.invokeOnCancellation(CancellableContinuation.kt:208) at kotlinx.coroutines.CancellableContinuationImpl.invokeOnCancellation(CancellableContinuationImpl.kt:393) at io.smallrye.mutiny.coroutines.UniKt.awaitSuspending(Uni.kt:37) at org.example.HelloClient$$QuarkusRestClientInterface.longRunning(Unknown Source) at org.example.HelloClient$$CDIWrapper.longRunning(Unknown Source) at org.example.HelloClient$$CDIWrapper_ClientProxy.longRunning(Unknown Source) at org.example.CallCancelResource$cancel2$2$1.invokeSuspend(ExampleResource.kt:79) at org.example.CallCancelResource$cancel2$2$1.invoke(ExampleResource.kt) at org.example.CallCancelResource$cancel2$2$1.invoke(ExampleResource.kt) at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturnIgnoreTimeout(Undispatched.kt:72) at kotlinx.coroutines.TimeoutKt.setupTimeout(Timeout.kt:148) at kotlinx.coroutines.TimeoutKt.withTimeoutOrNull(Timeout.kt:104) at org.example.CallCancelResource$cancel2$2.invokeSuspend(ExampleResource.kt:78) at org.example.CallCancelResource$cancel2$2.invoke(ExampleResource.kt) at org.example.CallCancelResource$cancel2$2.invoke(ExampleResource.kt) at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:61) at kotlinx.coroutines.CoroutineScopeKt.coroutineScope(CoroutineScope.kt:261) at org.example.CallCancelResource.cancel2$suspendImpl(ExampleResource.kt:75) at org.example.CallCancelResource.cancel2(ExampleResource.kt) at org.example.CallCancelResource$quarkuscoroutineinvoker$cancel2_e48d88832a4405f583c35a3f01a15c39b2d4d137.invokeCoroutine(Unknown Source) at org.jboss.resteasy.reactive.server.runtime.kotlin.CoroutineInvocationHandler$handle$job$1.invokeSuspend(CoroutineInvocationHandler.kt:48) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104) at org.jboss.resteasy.reactive.server.runtime.kotlin.VertxDispatcher.dispatch$lambda$0(ApplicationCoroutineScope.kt:45) at io.vertx.core.impl.ContextInternal.dispatch(ContextInternal.java:279) at io.vertx.core.impl.ContextInternal.dispatch(ContextInternal.java:261) at io.vertx.core.impl.ContextInternal.lambda$runOnContext$0(ContextInternal.java:59) at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:173) at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:166) at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:469) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569) at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:994) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.base/java.lang.Thread.run(Thread.java:840) Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [TimeoutCoroutine(timeMillis=10){Cancelling}@631ffae5, VertxDispatcher@48ac8e1c] Caused by: java.lang.NullPointerException: Cannot invoke "io.vertx.core.http.HttpClientRequest.reset()" because the return value of "org.jboss.resteasy.reactive.client.impl.RestClientRequestContext.getHttpClientRequest()" is null at org.jboss.resteasy.reactive.client.impl.UniInvoker$1.run(UniInvoker.java:49) at io.smallrye.context.impl.wrappers.SlowContextualRunnable.run(SlowContextualRunnable.java:19) at io.smallrye.mutiny.operators.uni.UniOnCancellation$UniOnCancellationProcessor.cancel(UniOnCancellation.java:64) at io.smallrye.mutiny.helpers.UniCallbackSubscriber.cancel(UniCallbackSubscriber.java:83) at io.smallrye.mutiny.coroutines.UniKt$awaitSuspending$2$3$1.invoke(Uni.kt:37) at io.smallrye.mutiny.coroutines.UniKt$awaitSuspending$2$3$1.invoke(Uni.kt:37) at kotlinx.coroutines.CancelHandler$UserSupplied.invoke(CancellableContinuationImpl.kt:660) at kotlinx.coroutines.CancellableContinuationImpl.callCancelHandler(CancellableContinuationImpl.kt:245) ... 37 more ```I also noticed an intermittent exception in Vert.x when reset is used. It doesn't check if the request exists before popping from the stack trace
|
Nice :( Thanks a lot for checking! @cescoffier this seems like a Vert.x bug |
I have a project for easy testing set up at https://github.com/calebkiage/quarkus-kotlin-cancellation-test that you can use as well for quick tests. |
Yes, that looks like a vert.x bug. @calebkiage can you open an issue in https://github.com/eclipse-vertx/vert.x |
It looks like the vertx bug was fixed. |
I have rebased the PR onto |
It seems to be working now stack trace2025-02-20 01:57:52,920 INFO [org.exa.CallCancelResource] (vert.x-eventloop-thread-1) calling /long/a with timeout 10 ms however, there's an exception that is printed in some instances after a quarkusDev restart: stack trace
Caused by: java.lang.NullPointerException: Cannot invoke "io.vertx.core.http.HttpClientRequest.reset()" because the return value of "org.jboss.resteasy.reactive.client.impl.RestClientRequestContext.getHttpClientRequest()" is null |
This comment has been minimized.
This comment has been minimized.
The latest update to the PR should fix that issue as well |
Status for workflow
|
Thanks. The exception isn't thrown anymore, but it looks like the first cancellation doesn't work. stack trace
|
Thanks for checking. By first you mean what exactly? |
The first request after the server starts doesn't cancel the request. I've attached logs. Instead of throwing an exception, resetting doesn't happen. |
Thanks. I'll have a look later. |
Can you provide some pointers on how to reproduce the issue using the sample you added above? |
Hi, sure. You should run the sample:
then in another terminal, run
The following line should NOT be in the logs, but it is:
The expectation is that the ExampleResource should log:
|