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

Throw fatalError when scheduling on shutdown EL if SWIFTNIO_STRICT is set #2190

Merged
merged 7 commits into from
Jun 14, 2022

Conversation

simonjbeaumont
Copy link
Contributor

Motivation:

When scheduling a task on an EventLoop that is shutdown an error message is printed to stdout which also warns that this will trigger a fatal error in future versions on NIO. #2153 suggests that we should support opting in to fatal errors now by means of an environment variable. It also suggests that any non-fatal error message should be printed to stderr, not stdout.

Modifications:

  • Trigger fatalError when scheduling tasks if event loop is shutdown when the SWIFTNIO_STRICT environment variable is set to something that looks like boolean true.
  • When SWIFTNIO_STRICT is not true, continue to print error message, but to stderr.

Result:

Fixes #2153.

@Lukasa Lukasa added patch-version-bump-only For PRs that when merged will only cause a bump of the patch version, ie. 1.0.x -> 1.0.(x+1) 🔼 needs-minor-version-bump For PRs that when merged cause a bump of the minor version, ie. 1.x.0 -> 1.(x+1).0 and removed patch-version-bump-only For PRs that when merged will only cause a bump of the patch version, ie. 1.0.x -> 1.0.(x+1) labels Jun 14, 2022
Copy link
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Thanks for this, this looks good! We have a few integration tests that attempt to test our crashing behaviours: can we add a test for this one?

Sources/NIOPosix/SelectableEventLoop.swift Outdated Show resolved Hide resolved
@simonjbeaumont
Copy link
Contributor Author

Thanks for this, this looks good! We have a few integration tests that attempt to test our crashing behaviours: can we add a test for this one?

Ah, cool. I had a test for this locally in the unit tests to check crashes which I obviously couldn't add. Good to know there's a place for such a test, I'll see if I can put one in.

Signed-off-by: Si Beaumont <beaumont@apple.com>
Signed-off-by: Si Beaumont <beaumont@apple.com>
@simonjbeaumont
Copy link
Contributor Author

Addressed comments and added CrashTest.

Copy link
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

LGTM, nice patch!

@Lukasa Lukasa enabled auto-merge (squash) June 14, 2022 11:10
@Lukasa Lukasa merged commit 69bb75d into apple:main Jun 14, 2022
@ktoso
Copy link
Member

ktoso commented Aug 3, 2022

Late to the party, thanks for solving this! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔼 needs-minor-version-bump For PRs that when merged cause a bump of the minor version, ie. 1.x.0 -> 1.(x+1).0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Environment var to make "Cannot schedule tasks on an EventLoop that has already shut down." crash
3 participants