From a45e61cc398c5817ac39f60e3b136af9fa1887bc Mon Sep 17 00:00:00 2001 From: Seppo Tomperi Date: Thu, 1 Apr 2021 13:53:34 +0300 Subject: [PATCH] Fixed a data race that occasionally causes a crash if webSocketTransport.closeConnection() and webSocketTransport.initServer() are called in succession. Fix was verified with Xcode Thread sanitizer --- Sources/ApolloWebSocket/WebSocketTransport.swift | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Sources/ApolloWebSocket/WebSocketTransport.swift b/Sources/ApolloWebSocket/WebSocketTransport.swift index cb2b499467..783b04bc3f 100644 --- a/Sources/ApolloWebSocket/WebSocketTransport.swift +++ b/Sources/ApolloWebSocket/WebSocketTransport.swift @@ -215,12 +215,13 @@ public class WebSocketTransport { } public func initServer() { - self.acked = false + processingQueue.async { + self.acked = false - if let str = OperationMessage(payload: self.connectingPayload, type: .connectionInit).rawMessage { - write(str, force:true) + if let str = OperationMessage(payload: self.connectingPayload, type: .connectionInit).rawMessage { + write(str, force:true) + } } - } public func closeConnection() {