     public var origin: String?
     public var timeout = 5
     public var isConnected: Bool {
-        return connected
+        connectedMutex.lock()
+        let isConnected = connected
+        connectedMutex.unlock()
+        return isConnected
     }
 
     public var currentURL: URL { return url }

                    let resIn = SSLSetEnabledCiphers(sslContextIn, cipherSuites, cipherSuites.count)
                    let resOut = SSLSetEnabledCiphers(sslContextOut, cipherSuites, cipherSuites.count)
                    if resIn != errSecSuccess {
                        let error = self.errorWithDetail("Error setting ingoing cypher suites", code: UInt16(resIn))
                        disconnectStream(error)
                        return
                    }
                    if resOut != errSecSuccess {
                        let error = self.errorWithDetail("Error setting outgoing cypher suites", code: UInt16(resOut))
                        disconnectStream(error)
                        return
                    }
                }

//  The content below is the concatenation of the files in Starscream (https://github.com/daltoniam/Starscream)
//  with trivial warnings fixed, trailing spaces removed, and some access levels changed.
//
// Based on commit SHA 789264eeff101e, but without some docs fixes from ee993322c
// onwards, and without the compression support.

//////////////////////////////////////////////////////////////////////////////////////////////////
//
