Skip to content

Commit e8a210a

Browse files
committed
Was having issues with race conditions so switched the nextRequestId incrementation to be on the Main Actor thread.
1 parent 9c2d308 commit e8a210a

File tree

1 file changed

+0
-34
lines changed

1 file changed

+0
-34
lines changed

Sources/Citadel/SFTP/Client/SFTPClient.swift

-34
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,13 @@ public final class SFTPClient {
1111
fileprivate let channel: Channel
1212

1313
/// A monotonically increasing counter for gneerating request IDs.
14-
/// Causes a race condition
15-
// private var nextRequestId: UInt32 = 0
16-
17-
// private let syncQueue = DispatchQueue(label: "com.test.myQueue", attributes: .concurrent)
1814
private var _nextRequestId: UInt32 = 0
1915

2016
@MainActor
2117
private func incrementAndGetNextRequestId() -> UInt32 {
22-
// syncQueue.sync {
2318
self._nextRequestId &+= 1
2419
return _nextRequestId
25-
// }
2620
}
27-
// var nextRequestId: UInt32 {
28-
// get {
29-
// syncQueue.async(flags: .barrier) {
30-
// self.nextRequestId &+= 1
31-
// return _nextRequestId
32-
// }
33-
// }
34-
//// get {
35-
//// syncQueue.sync {
36-
//// print("In grab. \(self._nextRequestId)")
37-
//// return _nextRequestId
38-
//// }
39-
//// }
40-
//// incrementAndGrab() -> UInt32 {
41-
//// self.nextRequestId &+= 1
42-
//// }
43-
//// set {
44-
//// syncQueue.async(flags: .barrier) {
45-
//// print("In set. \(self._nextRequestId)")
46-
//// self._nextRequestId = newValue
47-
//// print("After set. \(self._nextRequestId)")
48-
//// }
49-
//// }
50-
// }
5121

5222
/// In-flight request ID tracker.
5323
fileprivate let responses: SFTPResponses
@@ -101,10 +71,6 @@ public final class SFTPClient {
10171
/// a response; that is handled by `sendRequest(_:)`.
10272
@MainActor internal func allocateRequestId() -> UInt32 {
10373
return incrementAndGetNextRequestId()
104-
// defer {
105-
// self.nextRequestId &+= 1
106-
// } syncQueue.sync {
107-
// return self.nextRequestId
10874
}
10975

11076
/// Sends an SFTP request. The request's ID is used to track the response.

0 commit comments

Comments
 (0)