-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 Kotlin coroutine handlers on connection closing #41705
Comments
/cc @geoand (kotlin) |
Thanks! Mind attaching the project you used to test this? |
@geoand, I've added a link to a sample project. |
🙏🏼 |
When the server part of Quarkus REST is not included, prior to this change, user's @Provider classes were not registered for reflection Relates to: quarkusio#41705
Have a look at #41710 - it resolves your issue, but it does raise a question for us :) |
Nice @geoand 👍 |
🙏 |
@geoand, I've tested version 3.13.0.CR1 and cancellation works for the server. I've however noticed that the client doesn't reset the connection. When using the vert.x client manually, I can trigger cancellation by resetting the connection and it works fine: withTimeoutOrNull(delayLong) {
suspendCancellableCoroutine { cont->
val options = HttpClientOptions().setDefaultHost("localhost").setDefaultPort(9000)
val client = ctx.vertx().createHttpClient(options)
client.request(io.vertx.core.http.HttpMethod.GET, "/long/a").onComplete { conn->
if (conn.succeeded()) {
cont.invokeOnCancellation {
// Trigger a connection reset on cancellation
conn.result().reset()
}
val request = conn.result()
request.send().onComplete { resp->
if (resp.succeeded()) {
val body = resp.result().body()
body.onComplete { bodyState->
if (bodyState.succeeded()) {
cont.resume(bodyState.result().toString(Charsets.UTF_8))
} else {
cont.resumeWithException(bodyState.cause())
}
}
} else {
cont.resumeWithException(resp.cause())
}
}
} else {
cont.resumeWithException(conn.cause())
}
}
}
} I think the generated clients should also call reset on cancellation. What do you think? |
I just started testing out Quarkus with Kotlin suspend handlers and it seems to work well. However, I noticed that these handlers don't support cancellation on request connection closing. I found a workaround, but it seems very cumbersome to add this to every request and would like to find out if there's a better way.
In the sample code below, endpoint
/long/a
cancels the delay by throwing theCancellationException
when the connection is closed, but/long/b
does not.Originally posted by @calebkiage in #41696
Sample project
The text was updated successfully, but these errors were encountered: