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

Fix suspect crash cause in 5.0.0 #72

Merged
merged 1 commit into from
May 10, 2019
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
33 changes: 16 additions & 17 deletions Sources/NTPConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,18 @@ final class NTPConnection {
func close(waitUntilFinished wait: Bool = false) {
let work = {
self.cancelTimer()
if let socket = self.socket, let source = self.source {
let disabledFlags = NTPConnection.callbackFlags |
kCFSocketAutomaticallyReenableDataCallBack |
kCFSocketAutomaticallyReenableReadCallBack |
kCFSocketAutomaticallyReenableWriteCallBack |
kCFSocketAutomaticallyReenableAcceptCallBack
CFSocketDisableCallBacks(socket, disabledFlags)
CFSocketInvalidate(socket)
CFRunLoopRemoveSource(CFRunLoopGetMain(), source, CFRunLoopMode.commonModes)
self.socket = nil
self.source = nil
self.debugLog("Connection closed \(self.address)")
}
if self.callbackPending {
Unmanaged.passUnretained(self).release()
self.callbackPending = false
}
guard let socket = self.socket, let source = self.source else { return }
let disabledFlags = NTPConnection.callbackFlags |
kCFSocketAutomaticallyReenableDataCallBack |
kCFSocketAutomaticallyReenableReadCallBack |
kCFSocketAutomaticallyReenableWriteCallBack |
kCFSocketAutomaticallyReenableAcceptCallBack
CFSocketDisableCallBacks(socket, disabledFlags)
CFSocketInvalidate(socket)
CFRunLoopRemoveSource(CFRunLoopGetMain(), source, CFRunLoopMode.commonModes)
self.socket = nil
self.source = nil
self.debugLog("Connection closed \(self.address)")
}

if wait {
Expand Down Expand Up @@ -207,6 +202,10 @@ private extension NTPConnection {
onComplete(self, result)
}
}
if callbackPending {
callbackPending = false
Unmanaged.passUnretained(self).release()
}
}

func requestTime() {
Expand Down