-
Notifications
You must be signed in to change notification settings - Fork 113
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
[core] Add cancellation handling for nextInvocation() #459
Conversation
This PR does not compile in swift 6 mode and I don't see an easy way around the issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My goodness. two comments have lingered here forever in pending. Just flushing those right now
546acc9
to
467d012
Compare
Re-wrote this. It is considerably simpler. Also fixed test to ensure it does check for cancellation |
} | ||
// wait a small amount to ensure we are waiting for continuation | ||
try await Task.sleep(for: .milliseconds(100)) | ||
group.cancelAll() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should check that the spawned task returns with a cancellation error indeed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't return cancellation. Currently returns isInClosedChannel. Not sure how to get it to return the cancellation error as I'm just closing the connection and waiting for it to clean up. I could catch the error and then check Task.isCancelled and throw a Cancellation error if it is cancelled but that seems a bit of a hack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really good! Mind adding the test check.
|
Currently the test check will fail. There isn't an easy way to indicate the connection was closed due to cancellation without some re-structuring. |
Looks like we're good to merge then. Thank you for having confirmed |
Allow
LambdaChannelHandler.nextInvocation
to be cancelled.Motivation:
If we want to use ServiceLifecycle with the lambda runtime the lambda runtime needs to be cancellable either via a ServiceLifecycle graceful shutdown or via Task cancellation. To avoid bringing in the ServiceLifecycle dependency this PR adds cancellation via Task cancellation handler.
Modifications:
Add
withTaskCancellationHandler
to nextInvocation which calls close on cancel.In
LambdaChannelHandler.channelInactive
resume continuation if state iswaitingForNextInvocation
Added
LambdaRuntimeClientTests.testCancellation
Result:
You can now cancel the runtime while it is waiting for the next invocation.