     // MARK: - Deinit
 
     deinit {
-        mutex.lock()
+        readyToWriteMutex.lock()
         readyToWrite = false
-        mutex.unlock()
+        readyToWriteMutex.unlock()
         cleanupStream()
         writeQueue.cancelAllOperations()
     }

        guard !didDisconnect else { return }
        didDisconnect = true
        isConnecting = false
        connected = false
        guard canDispatch else {return}
        callbackQueue.async { [weak self] in
            guard let s = self else { 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.

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