-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Introduce a new nonblocking run()
method on Application
#2938
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It has been my repeated experience that this must be marked
@MainActor
in order to work reliably.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.
Is that so? I've not needed that, shall I change it?
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.
Nothing in the server world should require
@MainActor
. Maybe @gwynne hit some Vapor thread-safety issues that were accidentally worked around by@MainActor
?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.
I thought so already @weissi
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.
@weissi Yeah, that was my assumption, but I lacked the necessary tooling (and spare moments) at the time to dig into it further. It's definitely not a real solution.
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.
@gwynne when you have a repro, try
swift build -c release --sanitize=thread
and then run thatThere 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.
@weissi Will do, but it occurred to me a few minutes ago that what probably happened is I ended up attempting to perform the stop from the same event loop on which the future would complete (before bridging back over to Concurrency), which was already invalid before async came along — after all, the old version is a
.wait()
, it's a guaranteed deadlock!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.
@gwynne is this PR a go then?
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.
There's still nothing in place that ensures that, essentially, awaiting the
onStop
promise happens on the same thread that calledstart()
- I specifically mean "thread" here, not "workqueue worker", which for concurrency at the moment will be a concurrent DispatchQueue and therefore might be any old OS-level thread. As best I can work out, the actual issue is that something in the lifecycle (during boot, or command running, server setup and teardown, whatever) makes an unspoken and probably completely accidental assumption of always being on the main thread/queue, so thatawait
ing the stop promise can effectively make it complete too soon, or never. Again, needs more investigation.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.
@gwynne I don't see how that potential scenario would differ from the existing implementation - which uses
.wait()
. There's no asynchronous/offloaded work happening insideapp.start()
that would cause the console command (defaults toserve
) to delay creating a server socket.While I'd concur if it's sub-optimal to - for example - create a TCP server socket descriptor in a non-blocking fashion, that would be out of scope for this PR and a breaking change. So what do you suggest we do?