Skip to content

[Concurrency] Prevent negative sleeps from sleeping forever. #82563

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 1 commit into from
Jun 30, 2025

Conversation

al45tair
Copy link
Contributor

Requests to sleep until a negative timestamp would result in sleeping until UINT64_MAX nanoseconds from the start of the relevant clock, which is about 585 years.

rdar://154346018

@al45tair al45tair requested a review from ktoso as a code owner June 27, 2025 10:10
@al45tair al45tair requested a review from mikeash June 27, 2025 10:10
@al45tair
Copy link
Contributor Author

@swift-ci Please smoke test

Copy link
Contributor

@ktoso ktoso left a comment

Choose a reason for hiding this comment

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

Nice catch Lgtm

Requests to sleep until a negative timestamp would result in sleeping
until `UINT64_MAX` nanoseconds from the start of the relevant clock,
which is about 585 years.

rdar://154346018
@al45tair
Copy link
Contributor Author

Just updated it to check leeway as well (which I noticed while trying to cherry pick to 6.2), since I think Dispatch may internally add these together, which could also cause trouble. Much less likely to sleep with negative leeway though.

@al45tair
Copy link
Contributor Author

@swift-ci Please smoke test

Copy link
Contributor

@mikeash mikeash left a comment

Choose a reason for hiding this comment

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

It would be better if a negative sleep caused execution to resume before the sleep call, but I suppose this will do for now.

@al45tair al45tair merged commit f2c820a into swiftlang:main Jun 30, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants