         for socket in self.sockets {
             socket.shutdwn()
         }
-        self.sockets.removeAll(keepCapacity: true)
+        dispatch_sync(queue) {
+            self.sockets.removeAll(keepCapacity: true)
+        }
         socket.release()
         self.state = .Stopped
     }

    }
}

public enum HttpServerIOState: Int{
    case Starting
    case Running
    case Stopping

        self.state = .Starting
        self.socket = try Socket.tcpSocketForListen(port, forceIPv4: forceIPv4)
        dispatch_async(dispatch_get_global_queue(priority, 0)) { [weak self] in
            guard let `self` = self else { return }
            guard self.operating else { return }
            while let socket = try? self.socket.acceptClientSocket() {
                dispatch_async(dispatch_get_global_queue(priority, 0), { [weak self] in
                    guard let `self` = self else { return }
                    guard self.operating else { return }
                    dispatch_async(self.queue) {
                        self.sockets.insert(socket)
                    }
                    self.handleConnection(socket)
                    dispatch_async(self.queue) {
                        self.sockets.remove(socket)
                    }
                })
            }
            self.stop()
        }
        self.state = .Running
    }
