 
     /// Check if the socket is idle, and if so, call close()
     func closeIfIdleSocket() {
+        if !self.responseCompleted {
+            //We're in the middle of a connection - we're not idle
+            return
+        }
         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 is complete and we should close the socket
    public func responseCompleteCloseWriter() {
        self.socketWriterQueue.async { [weak self] in
            self?.responseCompleted = true
            self?.close()
        }
    }


    /// 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()
            }
