Skip to content

Make _MultiHandle timeout timer non-repeatable #4858

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
May 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ class _TimeoutSource {
let delay = UInt64(max(1, milliseconds - 1))
let start = DispatchTime.now() + DispatchTimeInterval.milliseconds(Int(delay))

rawSource.schedule(deadline: start, repeating: .milliseconds(Int(delay)), leeway: (milliseconds == 1) ? .microseconds(Int(1)) : .milliseconds(Int(1)))
rawSource.schedule(deadline: start, repeating: .never, leeway: (milliseconds == 1) ? .microseconds(Int(1)) : .milliseconds(Int(1)))
rawSource.setEventHandler(handler: handler)
rawSource.resume()
}
Expand All @@ -384,13 +384,12 @@ fileprivate extension URLSession._MultiHandle {
timeoutSource = nil
queue.async { self.timeoutTimerFired() }
case .milliseconds(let milliseconds):
if (timeoutSource == nil) || timeoutSource!.milliseconds != milliseconds {
//TODO: Could simply change the existing timer by using DispatchSourceTimer again.
let block = DispatchWorkItem { [weak self] in
self?.timeoutTimerFired()
}
timeoutSource = _TimeoutSource(queue: queue, milliseconds: milliseconds, handler: block)
//TODO: Could simply change the existing timer by using DispatchSourceTimer again.
let block = DispatchWorkItem { [weak self] in
self?.timeoutTimerFired()
}
// Note: Previous timer instance would cancel internal Dispatch timer in deinit
timeoutSource = _TimeoutSource(queue: queue, milliseconds: milliseconds, handler: block)
}
}
enum _Timeout {
Expand Down