Skip to content

Commit fae511f

Browse files
authored
bump version to 1.0.3
2 parents 1046735 + 9bca1b8 commit fae511f

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Changelog
22

33

4+
## 1.0.3 - (2025-07-02)
5+
6+
47
## 1.0.2 - (2025-06-10)
58

69
## 1.0.1 (2024-09-27)

Sources/AWSAppSyncApolloExtensions/Utilities/PackageInfo.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import AppKit
2121

2222
class PackageInfo {
2323

24-
private static let version = "1.0.2"
24+
private static let version = "1.0.3"
2525

2626
@MainActor
2727
private static var os: (name: String, version: String) = {

Sources/AWSAppSyncApolloExtensions/Websocket/AppSyncWebSocketClient.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,24 @@ public class AppSyncWebSocketClient: NSObject, ApolloWebSocket.WebSocketClient,
1717

1818
// MARK: - ApolloWebSocket.WebSocketClient
1919

20-
public var request: URLRequest
2120
public var delegate: ApolloWebSocket.WebSocketClientDelegate?
2221
public var callbackQueue: DispatchQueue
2322

23+
private let requestLock = NSLock()
24+
private var _request: URLRequest
25+
public var request: URLRequest {
26+
get {
27+
requestLock.lock()
28+
defer { requestLock.unlock() }
29+
return _request
30+
}
31+
set {
32+
requestLock.lock()
33+
defer { requestLock.unlock() }
34+
_request = newValue
35+
}
36+
}
37+
2438
// MARK: - Public
2539

2640
public var publisher: AnyPublisher<AppSyncWebSocketEvent, Never> {
@@ -71,7 +85,7 @@ public class AppSyncWebSocketClient: NSObject, ApolloWebSocket.WebSocketClient,
7185
callbackQueue: DispatchQueue,
7286
authorizer: AppSyncAuthorizer
7387
) {
74-
self.request = URLRequest(url: appSyncRealTimeEndpoint(endpointURL))
88+
self._request = URLRequest(url: appSyncRealTimeEndpoint(endpointURL))
7589
self.delegate = delegate
7690
self.callbackQueue = callbackQueue
7791
self.authorizer = authorizer

Tests/AWSAppSyncApolloExtensionsTests/Websocket/AppSyncWebSocketClientTests.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,37 @@ final class AppSyncWebSocketClientTests: XCTestCase {
119119
await fulfillment(of: [messageReceivedExpectation], timeout: 5)
120120
}
121121

122+
func testConcurrentURLRequestAccess() async {
123+
let endpoint = URL(string: "https://abc.appsync-api.us-east-1.amazonaws.com/graphql")!
124+
125+
let websocket = AppSyncWebSocketClient(
126+
endpointURL: endpoint,
127+
authorizer: APIKeyAuthorizer(apiKey: "apiKey"))
128+
129+
let raceConditionExpectation = expectation(description: "Race condition test")
130+
raceConditionExpectation.expectedFulfillmentCount = 2
131+
132+
let iterations = 1000
133+
134+
// Thread 1: Continuous reading
135+
DispatchQueue.global(qos: .userInitiated).async {
136+
for _ in 0..<iterations {
137+
_ = websocket.request.value(forHTTPHeaderField: "test-header")
138+
}
139+
raceConditionExpectation.fulfill()
140+
}
141+
142+
// Thread 2: Continuous writing
143+
DispatchQueue.global(qos: .userInitiated).async {
144+
for i in 0..<iterations {
145+
websocket.request.setValue("value-\(i)", forHTTPHeaderField: "test-header")
146+
}
147+
raceConditionExpectation.fulfill()
148+
}
149+
150+
await fulfillment(of: [raceConditionExpectation], timeout: 5)
151+
}
152+
122153
private func verifyConnected(
123154
_ webSocketClient: AppSyncWebSocketClient,
124155
autoConnectOnNetworkStatusChange: Bool = false,

0 commit comments

Comments
 (0)