     
     /// Called by the parser to let us know that a response is complete and we should close the socket
     public func responseCompleteCloseWriter() {
+        self.responseCompleted = true
         self.socketWriterQueue.async { [weak self] in
-            self?.responseCompleted = true
             self?.close()
         }
     }


    /// Check if the socket is idle, and if so, call close()
    func closeIfIdleSocket() {
        let now = Date().timeIntervalSinceReferenceDate
        if let keepAliveUntil = parser?.keepAliveUntil, now >= keepAliveUntil {
            print("Closing idle socket \(socketFD)")


    /// Called by the parser to let us know that a response has started being created
    public func responseBeginning() {
        self.responseCompleted = false
    }

    /// Called by the parser to let us know that a response is complete, and we can close after timeout
    public func responseComplete() {
        self.responseCompleted = true
        self.socketWriterQueue.async { [weak self] in
            if self?.readerSource?.isCancelled ?? true {
                self?.close()
            }
