From fc1cfae9ca7ac0f9fe1f696a996a652cd798299b Mon Sep 17 00:00:00 2001 From: "Dr. Brandon Wiley" Date: Thu, 21 Jan 2021 17:31:29 -0600 Subject: [PATCH] Fixed locking on failure --- Sources/Transmission/Connection.swift | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Sources/Transmission/Connection.swift b/Sources/Transmission/Connection.swift index 7966d94..1fbd773 100644 --- a/Sources/Transmission/Connection.swift +++ b/Sources/Transmission/Connection.swift @@ -45,13 +45,13 @@ public class Connection self.connectLock.leave() return case .cancelled: - self.connectLock.leave() + self.failConnect() return case .failed(_): - self.connectLock.leave() + self.failConnect() return - case .waiting(let error): - self.connectLock.leave() + case .waiting(_): + self.failConnect() return default: return @@ -64,6 +64,13 @@ public class Connection guard success else {return nil} } + + func failConnect() + { + self.connection.stateUpdateHandler = nil + self.connection.cancel() + self.connectLock.leave() + } public func read(size: Int) -> Data? {