@@ -574,28 +574,31 @@ internal final class EtcdHttpClient: @unchecked Sendable {
574574
575575 group. addTask {
576576 let data : Data = try await withCheckedThrowingContinuation { continuation in
577- self . lock. lock ( )
578- guard self . sessionGeneration == generation, let currentSession = self . session else {
579- self . lock . unlock ( )
580- continuation . resume ( throwing : EtcdError . notConnected )
581- return
582- }
583- let task = currentSession . dataTask ( with : request ) { data , _ , error in
584- if let error {
585- // URLError.cancelled is expected when we cancel after timeout
586- if ( error as? URLError ) ? . code == . cancelled {
587- continuation. resume ( returning : data ?? Data ( ) )
588- } else {
589- continuation . resume ( throwing : error )
577+ let result : ( session : URLSession , task : URLSessionDataTask ) ? = self . lock. withLock {
578+ guard self . sessionGeneration == generation, let currentSession = self . session else {
579+ return nil
580+ }
581+ let dataTask = currentSession . dataTask ( with : request ) { data , _ , error in
582+ if let error {
583+ // URLError.cancelled is expected when we cancel after timeout
584+ if ( error as? URLError ) ? . code == . cancelled {
585+ continuation . resume ( returning : data ?? Data ( ) )
586+ } else {
587+ continuation. resume ( throwing : error )
588+ }
589+ return
590590 }
591- return
591+ continuation . resume ( returning : data ?? Data ( ) )
592592 }
593- continuation. resume ( returning: data ?? Data ( ) )
593+ self . currentTask = dataTask
594+ return ( currentSession, dataTask)
594595 }
595- self . currentTask = task
596- self . lock. unlock ( )
597- collectedData. setTask ( task)
598- task. resume ( )
596+ guard let result else {
597+ continuation. resume ( throwing: EtcdError . notConnected)
598+ return
599+ }
600+ collectedData. setTask ( result. task)
601+ result. task. resume ( )
599602 }
600603 return Self . parseWatchEvents ( from: data)
601604 }
@@ -1062,10 +1065,7 @@ internal final class EtcdHttpClient: @unchecked Sendable {
10621065 return
10631066 }
10641067
1065- guard let identity = identityRef as? SecIdentity else {
1066- completionHandler ( . cancelAuthenticationChallenge, nil )
1067- return
1068- }
1068+ let identity = unsafeBitCast ( identityRef, to: SecIdentity . self)
10691069 let credential = URLCredential (
10701070 identity: identity,
10711071 certificates: nil ,
@@ -1122,7 +1122,7 @@ internal final class EtcdHttpClient: @unchecked Sendable {
11221122 }
11231123
11241124 // Export to PKCS#12
1125- var exportItems : CFArray ?
1125+ let exportItems : CFArray ? = nil
11261126 guard let identity = createIdentity ( certificate: cert, privateKey: privateKey) else {
11271127 return nil
11281128 }
0 commit comments