         }
         
         guard !isForcedClose(task.response as? HTTPURLResponse) else {
+            close()
             callback?.pyroEventSource(self, didReceiveError: PyroEventSourceError.forcedClose)
-            close()
             return
         }
         
         if let responseError = response.isErroneous(task.response as? HTTPURLResponse) {
+            close()
             callback?.pyroEventSource(self, didReceiveError: responseError)
-            close()
             
         } else {
             let message = parser.parse(data)

    }
    
    public func close() {
        session.invalidateAndCancel()
        session = nil
        state = .closed
    }

    }
    
    public func urlSession(_ session: URLSession, dataTask task: URLSessionDataTask, didReceive httpResponse: URLResponse, completionHandler: @escaping (URLSession.ResponseDisposition) -> Void) {
        if let responseError = response.isErroneous(httpResponse as? HTTPURLResponse) {
            close()
            callback?.pyroEventSource(self, didReceiveError: responseError)
            
        } else {
            state = .open
            completionHandler(.allow)
        }
    }
    
    public func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
        close()
        
        guard !isForcedClose(task.response as? HTTPURLResponse) else {
            callback?.pyroEventSource(self, didReceiveError: PyroEventSourceError.forcedClose)
            return
        }
        
        if let responseError = response.isErroneous(task.response as? HTTPURLResponse) {
            callback?.pyroEventSource(self, didReceiveError: responseError)
        }
    }
}
