Skip to content
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

Make Request Sendable #3093

Merged
merged 32 commits into from
Nov 6, 2023
Merged

Make Request Sendable #3093

merged 32 commits into from
Nov 6, 2023

Conversation

0xTim
Copy link
Member

@0xTim 0xTim commented Nov 1, 2023

Final stage of Vapor's Sendable journey as Request is now Sendable.

There should be no more Sendable warnings in Vapor, even with complete concurrency checking turned on.

@0xTim 0xTim added the semver-minor Contains new API label Nov 1, 2023
@0xTim 0xTim marked this pull request as ready for review November 1, 2023 18:36
@0xTim 0xTim requested a review from gwynne as a code owner November 1, 2023 18:36
@0xTim
Copy link
Member Author

0xTim commented Nov 1, 2023

This was surprisingly easy in the end. Tried to reduce the locks where possible, I've added individual locks to where it's likely to be accessed concurrently

@0xTim 0xTim linked an issue Nov 1, 2023 that may be closed by this pull request
@codecov-commenter
Copy link

codecov-commenter commented Nov 1, 2023

Codecov Report

Merging #3093 (7b4f347) into main (3bf4e73) will increase coverage by 0.00%.
Report is 3 commits behind head on main.
The diff coverage is 82.82%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3093   +/-   ##
=======================================
  Coverage   76.23%   76.24%           
=======================================
  Files         211      211           
  Lines        7904     7998   +94     
=======================================
+ Hits         6026     6098   +72     
- Misses       1878     1900   +22     
Files Coverage Δ
...ces/Vapor/Authentication/AuthenticationCache.swift 84.84% <100.00%> (+0.97%) ⬆️
Sources/Vapor/Authentication/Authenticator.swift 57.89% <ø> (ø)
Sources/Vapor/Authentication/GuardMiddleware.swift 100.00% <ø> (ø)
...rces/Vapor/Authentication/RedirectMiddleware.swift 83.33% <ø> (ø)
Sources/Vapor/Commands/ServeCommand.swift 86.20% <100.00%> (+1.02%) ⬆️
.../Vapor/Concurrency/RoutesBuilder+Concurrency.swift 60.97% <ø> (ø)
...rces/Vapor/Concurrency/WebSocket+Concurrency.swift 92.72% <ø> (ø)
Sources/Vapor/HTTP/Headers/HTTPMediaType.swift 78.72% <ø> (ø)
Sources/Vapor/HTTP/Server/HTTPServerHandler.swift 93.87% <100.00%> (ø)
Sources/Vapor/Request/Request+Body.swift 81.57% <100.00%> (ø)
... and 11 more

Copy link
Contributor

@MahdiBM MahdiBM left a comment

Choose a reason for hiding this comment

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

Looks good but some requested changes.

I also see one probably-resolvable warning in "Development" on 5.9:

/__w/vapor/vapor/Sources/Development/routes.swift:274:36: warning: converting non-sendable function value to '@sendable (Request) async throws -> some AsyncResponseEncodable' may introduce data races
asyncRoutes.get("opaque", use: opaqueRouteTester)

.devcontainer/devcontainer.json Outdated Show resolved Hide resolved
Sources/Vapor/Commands/ServeCommand.swift Outdated Show resolved Hide resolved
Sources/Vapor/HTTP/Headers/HTTPCookies.swift Show resolved Hide resolved
Sources/Vapor/HTTP/Headers/HTTPCookies.swift Show resolved Hide resolved
Sources/Vapor/Commands/ServeCommand.swift Show resolved Hide resolved
Sources/Vapor/Routing/Route.swift Show resolved Hide resolved
.gitignore Show resolved Hide resolved
@@ -1,33 +1,94 @@
import NIOHTTP1
import RoutingKit
@preconcurrency import RoutingKit
import NIOConcurrencyHelpers

Copy link
Member

Choose a reason for hiding this comment

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

I would hasten to point out that there's nothing held by Route that inherently makes it non-Sendable in theory- or for that matter, that justifies it being a reference type rather than a value type in the first place (or for that matter, that justifies it being mutable at all!). I know that can't be changed without breaking API, but it does suggest that @unchecked Sendable ("I know what I'm doing, punish me if I hork it up") might be a better choice than a bunch of locking no one should be hitting to begin with.

Copy link
Member Author

Choose a reason for hiding this comment

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

The only thing that requires this here is PathComponent which we can make Sendable and I'll do in another PR when I tackle RoutingKit. That one I want to be very careful with though for obvious reasons

Copy link
Member Author

Choose a reason for hiding this comment

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

Wrt to the whole thing of Route and unchecked Sendable I'm planning on doing a better audit of Vapor things, deprecating thing and then introducing a new AsyncRoute in it's place

Copy link
Member

@gwynne gwynne left a comment

Choose a reason for hiding this comment

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

Per comments above

@0xTim
Copy link
Member Author

0xTim commented Nov 4, 2023

@MahdiBM that's an annoying Swift bug with complete concurrency checking and nothing we can do at the moment until it's fixed in Swift

@MahdiBM
Copy link
Contributor

MahdiBM commented Nov 4, 2023

O it's that bug... you can just open up the closure and the bug will go away. Though I'm fine with it either way since it's a bug.

@0xTim 0xTim requested a review from gwynne November 4, 2023 17:37
@0xTim 0xTim merged commit 3744d42 into main Nov 6, 2023
17 of 18 checks passed
@0xTim 0xTim deleted the sendable-request branch November 6, 2023 11:37
@penny-for-vapor
Copy link

These changes are now available in 4.86.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-minor Contains new API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vapor.Request isn't thread safe but a mutable class
4 participants