Skip to content

Make the ResponseAccumulator Sendable #838

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

Merged
merged 3 commits into from
Apr 30, 2025

Conversation

glbrntt
Copy link
Collaborator

@glbrntt glbrntt commented Apr 30, 2025

Motivation:

The response accumulator is a delegate which must be sendable as it's passed across isolation domains.

Modifications:

  • Make delegates have a sendable requirement
  • Make the response accumulator sendable

Result:

Delegates, and the response accumulator, are sendable

Motivation:

The response accumulator is a delegate which must be sendable as it's
passed across isolation domains.

Modifications:

- Make delegates have a sendable requirement
- Make the response accumulator sendable

Result:

Delegates, and the response accumulator, are sendable
@glbrntt glbrntt added the 🆕 semver/minor Adds new public API. label Apr 30, 2025
if self.requestMethod != .HEAD,
let contentLength = head.headers.first(name: "Content-Length"),
let announcedBodySize = Int(contentLength),
announcedBodySize > self.maxBodySize
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I suggest that we pull this computation out of the lock?

@@ -894,30 +910,35 @@ extension HTTPClient {
///
/// Will be created by the library and could be used for obtaining
/// `EventLoopFuture<Response>` of the execution or cancellation of the execution.
public final class Task<Response> {
@preconcurrency
public final class Task<Response: Sendable> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the unchecked Sendable still needed for this? Can it be checked?

}
}

private var _isCancelled: Bool = false
private var _taskDelegate: HTTPClientTaskDelegate?
private let lock = NIOLock()
private let makeOrGetFileIOThreadPool: () -> NIOThreadPool
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this needs an @Sendable.

@@ -894,30 +910,35 @@ extension HTTPClient {
///
/// Will be created by the library and could be used for obtaining
/// `EventLoopFuture<Response>` of the execution or cancellation of the execution.
public final class Task<Response> {
@preconcurrency
public final class Task<Response: Sendable> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, how sure are we that this constraint is needed?

@glbrntt glbrntt requested a review from Lukasa April 30, 2025 13:07
@Lukasa Lukasa merged commit 7e6f9cf into swift-server:main Apr 30, 2025
22 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants