                             sock.readData(to: self.headerTerminator, withTimeout: Timeouts.header.rawValue, tag: DataTag.tag_HEADER.rawValue)
                         } else {
                             peer.state = .notConnected
-                            sock.delegate = nil
+                            sock.synchronouslySetDelegate(nil)
                             sock.disconnect()
                             peer.socket = nil
                             NSLog("... rejected (by my delegate), or no longer connected")

        // loop through peers, disconenct all sockets
        for peer in self.peers {
            NSLog("BluepeerObject disconnectSession: disconnecting \(peer.displayName)")
            peer.socket?.delegate = nil // we don't want to run our disconnection logic below
            peer.socket?.disconnect()
            peer.socket = nil
            peer.dnsService?.endResolve()

                    
                    self.stopBrowsing() // stop browsing once user has done something. Destroys all HHService except this one!
                    
                    if let oldSocket = peer.socket {
                        NSLog("**** BluepeerObject: PEER ALREADY HAD SOCKET, DESTROYING...")
                        oldSocket.synchronouslySetDelegate(nil)
                        oldSocket.disconnect()
                        peer.socket = nil
                    }
                    
                    peer.socket = GCDAsyncSocket.init(delegate: self, delegateQueue: self.socketQueue)
                    peer.socket?.isIPv4PreferredOverIPv6 = false
                    peer.state = .connecting
                    try peer.socket?.connect(toAddress: sockdata, viaInterface: chosenAddress.interfaceName, withTimeout: timeoutForInvite)
                } catch {
