-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
Cancel on inbound close #627
Conversation
@@ -60,10 +65,100 @@ public struct Request: Sendable { | |||
self.body = .init(buffer: byteBuffer) | |||
return byteBuffer | |||
} | |||
|
|||
public func cancelOnInboundClose<Value: Sendable>(_ process: @escaping @Sendable (Request) async throws -> Value) async throws -> Value { |
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 should be part of the (Core)RequestContext instead
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.
Server
needs access to this object and it knows nothing about RequestContexts so not sure how we can do this.
Need #629 to really make this useful |
Pull request benchmark comparison [ubuntu-latest] with 'main' run at 2024-12-06T16:00:32+00:00 |
Add support for cancelling a request when the inbound is closed.
There are limitations
request.cancelOnInboundClose
consumes the request bodyThe way it works. It runs a task group with one task reading the request inbound stream, and the other running the closure. To avoid the request inbound stream being iterated twice a new version of the request is constructed with a new inbound stream that is being fed by the first of the tasks.
If the request inbound stream hits a second http head (ie the next request) then that is stored in the request iteration state attached to Request.