Fix bug in Dispatch executor preventing long sleeps #64304
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.
Dispatch executor's swift_task_enqueueGlobalWithDelayImpl adds the requested delay to the current time and enqueues the job to run at that time. This has a bug when using a very large delay on the order of 2^63 to 2^64 nanoseconds because dispatch_time(), which is used to preform the now + delay calculation, returns DISPATCH_TIME_FOREVER. However, dispatch_after(), which is used to actually enqueue the job, has undefined behavior for this time; the result in practice is that the job is immediately run.
This change resolves the bug by leaking the job if the result of dispatch_time is DISPATCH_TIME_FOREVER. This should effectively be the same as the job getting delayed forever.
Radar-Id: rdar://problem/89455918