-
Notifications
You must be signed in to change notification settings - Fork 653
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
Clean up sendability in the bootstraps #3051
base: main
Are you sure you want to change the base?
Clean up sendability in the bootstraps #3051
Conversation
Sources/NIOPosix/Bootstrap.swift
Outdated
@@ -474,17 +479,17 @@ public final class ServerBootstrap { | |||
func fireThroughPipeline(_ future: EventLoopFuture<Void>, context: ChannelHandlerContext) { | |||
ctxEventLoop.assertInEventLoop() | |||
assert(ctxEventLoop === context.eventLoop) | |||
let loopBoundContext = context.loopBound | |||
let loopBoundValues = NIOLoopBound((context: context, self: self), eventLoop: context.eventLoop) |
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.
Can't we use the assume isolated APIs here?
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.
Yes, we can. Updated.
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.
Love it!
Unfortunately this has regressed allocations. For example, in |
Ok, hopefully #3055 should have resolved those regressions, so let's see. |
5840d79
to
31cea7b
Compare
Oh, it not only resolved those regressions, but led to a benchmark improvement. That's nice! |
d82ccfd
to
296ac85
Compare
Motivation:
The bootstraps are the next most obvious target for cleaning up Sendability issues. These issues are mostly just missing annotations, but there are a few places where we had actual latent threading bugs that were missed. A lot more of the control flow is made more explicit in this patch, and in general it should get a lot easier to be confident that the code is correct.
Modifications:
@Sendable
annotationsself
captures of bootstraps, which are notSendable
, and which could lead to real threading bugsstatic
to avoid needing to captureself
at all.Sendable
constraints on interior generic functions.Result:
Better safety, better correctness in the bootstraps.