[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. |
fabianfett
left a comment
There was a problem hiding this comment.
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.
we should check that the spawned task returns with a cancellation error indeed!
There was a problem hiding this comment.
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.
fabianfett
left a comment
There was a problem hiding this comment.
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.nextInvocationto 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
withTaskCancellationHandlerto nextInvocation which calls close on cancel.In
LambdaChannelHandler.channelInactiveresume continuation if state iswaitingForNextInvocationAdded
LambdaRuntimeClientTests.testCancellationResult:
You can now cancel the runtime while it is waiting for the next invocation.