From 0adf0250e7f363345117766f3689e4c3e669c910 Mon Sep 17 00:00:00 2001 From: Calvin Cestari Date: Thu, 31 Oct 2024 15:51:42 -0700 Subject: [PATCH] fix: Assign websocket callback queue before connecting (apollographql/apollo-ios-dev#529) --- Sources/ApolloWebSocket/WebSocketTransport.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sources/ApolloWebSocket/WebSocketTransport.swift b/Sources/ApolloWebSocket/WebSocketTransport.swift index 3cbcdef733..b68ee763d1 100644 --- a/Sources/ApolloWebSocket/WebSocketTransport.swift +++ b/Sources/ApolloWebSocket/WebSocketTransport.swift @@ -167,10 +167,14 @@ public class WebSocketTransport { self.addApolloClientHeaders(to: &self.websocket.request) self.websocket.delegate = self + // Keep the assignment of the callback queue before attempting to connect. There is the + // potential of a data race if the connection fails early and the disconnect logic reads + // the callback queue while it's being set. + self.websocket.callbackQueue = processingQueue + if config.connectOnInit { self.websocket.connect() } - self.websocket.callbackQueue = processingQueue } public func isConnected() -> Bool {