From b4c71a72f2ce36f469638a15d151ac594d2727a1 Mon Sep 17 00:00:00 2001
From: Julian Andres Klode <julian.klode@canonical.com>
Date: Mon, 29 Jun 2020 11:32:12 +0200
Subject: [PATCH] http: Always Close() the connection in Die()

If we reached Die() there was an issue with the server connection,
so we should always explicitly close it.
---
 methods/http.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/methods/http.cc b/methods/http.cc
index e72c612..d1f6aaa 100644
--- a/methods/http.cc
+++ b/methods/http.cc
@@ -695,6 +695,8 @@ ResultState HttpServerState::Die(RequestState &Req)
 {
    unsigned int LErrno = errno;
 
+   Close();
+
    // Dump the buffer to the file
    if (Req.State == RequestState::Data)
    {
@@ -722,7 +724,6 @@ ResultState HttpServerState::Die(RequestState &Req)
    if (In.IsLimit() == false && Req.State != RequestState::Header &&
        Persistent == true)
    {
-      Close();
       if (LErrno == 0)
       {
 	 _error->Error(_("Error reading from server. Remote end closed connection"));
@@ -741,7 +742,6 @@ ResultState HttpServerState::Die(RequestState &Req)
 	 return ResultState::TRANSIENT_ERROR;
 
       // We may have got multiple responses back in one packet..
-      Close();
       return ResultState::SUCCESSFUL;
    }
 
-- 
GitLab