Skip to content

Commit 897d49a

Browse files
authored
Replace Lock with NIOLock (#628)
SwiftNIO 2.42.0 has deprecated Lock and replaced it with a new NIOLock. This commit removes all uses of Lock and replaces them with NIOLock. Further, now, we must require SwiftNIO 2.42.0
1 parent 7f998f5 commit 897d49a

File tree

11 files changed

+24
-24
lines changed

11 files changed

+24
-24
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let package = Package(
2121
.library(name: "AsyncHTTPClient", targets: ["AsyncHTTPClient"]),
2222
],
2323
dependencies: [
24-
.package(url: "https://github.com/apple/swift-nio.git", from: "2.41.1"),
24+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.42.0"),
2525
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.22.0"),
2626
.package(url: "https://github.com/apple/swift-nio-http2.git", from: "1.19.0"),
2727
.package(url: "https://github.com/apple/swift-nio-extras.git", from: "1.13.0"),

Sources/AsyncHTTPClient/AsyncAwait/Transaction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class Transaction: @unchecked Sendable {
2929
let preferredEventLoop: EventLoop
3030
let requestOptions: RequestOptions
3131

32-
private let stateLock = Lock()
32+
private let stateLock = NIOLock()
3333
private var state: StateMachine
3434

3535
init(

Sources/AsyncHTTPClient/ConnectionPool/HTTPConnectionPool+Manager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extension HTTPConnectionPool {
3535

3636
private var state: State = .active
3737
private var _pools: [Key: HTTPConnectionPool] = [:]
38-
private let lock = Lock()
38+
private let lock = NIOLock()
3939

4040
private let sslContextCache = SSLContextCache()
4141

Sources/AsyncHTTPClient/ConnectionPool/HTTPConnectionPool.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protocol HTTPConnectionPoolDelegate {
2222
}
2323

2424
final class HTTPConnectionPool {
25-
private let stateLock = Lock()
25+
private let stateLock = NIOLock()
2626
private var _state: StateMachine
2727
/// The connection idle timeout timers. Protected by the stateLock
2828
private var _idleTimer = [Connection.ID: Scheduled<Void>]()

Sources/AsyncHTTPClient/HTTPClient.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ public class HTTPClient {
7575

7676
/// Shared thread pool used for file IO. It is lazily created on first access of ``Task/fileIOThreadPool``.
7777
private var fileIOThreadPool: NIOThreadPool?
78-
private let fileIOThreadPoolLock = Lock()
78+
private let fileIOThreadPoolLock = NIOLock()
7979

8080
private var state: State
81-
private let stateLock = Lock()
81+
private let stateLock = NIOLock()
8282

8383
internal static let loggingDisabled = Logger(label: "AHC-do-not-log", factory: { _ in SwiftLogNoOpLogHandler() })
8484

@@ -169,7 +169,7 @@ public class HTTPClient {
169169
Current eventLoop: \(eventLoop)
170170
""")
171171
}
172-
let errorStorageLock = Lock()
172+
let errorStorageLock = NIOLock()
173173
let errorStorage: UnsafeMutableTransferBox<Error?> = .init(nil)
174174
let continuation = DispatchWorkItem {}
175175
self.shutdown(requiresCleanClose: requiresCleanClose, queue: DispatchQueue(label: "async-http-client.shutdown")) { error in
@@ -256,7 +256,7 @@ public class HTTPClient {
256256
}
257257

258258
private func shutdownFileIOThreadPool(queue: DispatchQueue, _ callback: @escaping ShutdownCallback) {
259-
self.fileIOThreadPoolLock.withLockVoid {
259+
self.fileIOThreadPoolLock.withLock {
260260
guard let fileIOThreadPool = fileIOThreadPool else {
261261
callback(nil)
262262
return

Sources/AsyncHTTPClient/HTTPHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ extension HTTPClient {
657657

658658
private var _isCancelled: Bool = false
659659
private var _taskDelegate: HTTPClientTaskDelegate?
660-
private let lock = Lock()
660+
private let lock = NIOLock()
661661
private let makeOrGetFileIOThreadPool: () -> NIOThreadPool
662662

663663
/// The shared thread pool of a ``HTTPClient`` used for file IO. It is lazily created on first access.

Sources/AsyncHTTPClient/SSLContextCache.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import NIOCore
1919
import NIOSSL
2020

2121
final class SSLContextCache {
22-
private let lock = Lock()
22+
private let lock = NIOLock()
2323
private var sslContextCache = LRUCache<BestEffortHashableTLSConfiguration, NIOSSLContext>()
2424
private let offloadQueue = DispatchQueue(label: "io.github.swift-server.AsyncHTTPClient.SSLContextCache")
2525
}

Tests/AsyncHTTPClientTests/AsyncTestHelpers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ final class AsyncSequenceWriter<Element>: AsyncSequence, @unchecked Sendable {
4545
}
4646

4747
private var _state = State.buffering(.init(), nil)
48-
private let lock = Lock()
48+
private let lock = NIOLock()
4949

5050
public var hasDemand: Bool {
5151
self.lock.withLock {

Tests/AsyncHTTPClientTests/HTTP1ConnectionTests.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -595,12 +595,12 @@ class HTTP1ConnectionTests: XCTestCase {
595595
var _reads = 0
596596
var _channel: Channel?
597597

598-
let lock: Lock
598+
let lock: NIOLock
599599
let backpressurePromise: EventLoopPromise<Void>
600600
let messageReceived: EventLoopPromise<Void>
601601

602602
init(eventLoop: EventLoop) {
603-
self.lock = Lock()
603+
self.lock = NIOLock()
604604
self.backpressurePromise = eventLoop.makePromise()
605605
self.messageReceived = eventLoop.makePromise()
606606
}
@@ -612,7 +612,7 @@ class HTTP1ConnectionTests: XCTestCase {
612612
}
613613

614614
func willExecuteOnChannel(_ channel: Channel) {
615-
self.lock.withLockVoid {
615+
self.lock.withLock {
616616
self._channel = channel
617617
}
618618
}
@@ -623,7 +623,7 @@ class HTTP1ConnectionTests: XCTestCase {
623623

624624
func didReceiveBodyPart(task: HTTPClient.Task<Response>, _ buffer: ByteBuffer) -> EventLoopFuture<Void> {
625625
// We count a number of reads received.
626-
self.lock.withLockVoid {
626+
self.lock.withLock {
627627
self._reads += 1
628628
}
629629
// We need to notify the test when first byte of the message is arrived.
@@ -805,7 +805,7 @@ class AfterRequestCloseConnectionChannelHandler: ChannelInboundHandler {
805805
}
806806

807807
class MockConnectionDelegate: HTTP1ConnectionDelegate {
808-
private var lock = Lock()
808+
private var lock = NIOLock()
809809

810810
private var _hitConnectionReleased = 0
811811
private var _hitConnectionClosed = 0
@@ -821,13 +821,13 @@ class MockConnectionDelegate: HTTP1ConnectionDelegate {
821821
init() {}
822822

823823
func http1ConnectionReleased(_: HTTP1Connection) {
824-
self.lock.withLockVoid {
824+
self.lock.withLock {
825825
self._hitConnectionReleased += 1
826826
}
827827
}
828828

829829
func http1ConnectionClosed(_: HTTP1Connection) {
830-
self.lock.withLockVoid {
830+
self.lock.withLock {
831831
self._hitConnectionClosed += 1
832832
}
833833
}

Tests/AsyncHTTPClientTests/HTTP2ConnectionTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ class TestConnectionCreator {
235235
}
236236

237237
private var state: State = .idle
238-
private let lock = Lock()
238+
private let lock = NIOLock()
239239

240240
init() {}
241241

@@ -428,7 +428,7 @@ class TestHTTP2ConnectionDelegate: HTTP2ConnectionDelegate {
428428
self.lock.withLock { self._maxStreamSetting }
429429
}
430430

431-
private let lock = Lock()
431+
private let lock = NIOLock()
432432
private var _hitStreamClosed: Int = 0
433433
private var _hitGoAwayReceived: Int = 0
434434
private var _hitConnectionClosed: Int = 0
@@ -439,19 +439,19 @@ class TestHTTP2ConnectionDelegate: HTTP2ConnectionDelegate {
439439
func http2Connection(_: HTTP2Connection, newMaxStreamSetting: Int) {}
440440

441441
func http2ConnectionStreamClosed(_: HTTP2Connection, availableStreams: Int) {
442-
self.lock.withLockVoid {
442+
self.lock.withLock {
443443
self._hitStreamClosed += 1
444444
}
445445
}
446446

447447
func http2ConnectionGoAwayReceived(_: HTTP2Connection) {
448-
self.lock.withLockVoid {
448+
self.lock.withLock {
449449
self._hitGoAwayReceived += 1
450450
}
451451
}
452452

453453
func http2ConnectionClosed(_: HTTP2Connection) {
454-
self.lock.withLockVoid {
454+
self.lock.withLock {
455455
self._hitConnectionClosed += 1
456456
}
457457
}

Tests/AsyncHTTPClientTests/HTTPClientTestUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ struct CollectEverythingLogHandler: LogHandler {
11181118
var metadata: [String: String]
11191119
}
11201120

1121-
var lock = Lock()
1121+
var lock = NIOLock()
11221122
var logs: [Entry] = []
11231123

11241124
var allEntries: [Entry] {

0 commit comments

Comments
 (0)