]> git.saurik.com Git - apt.git/commitdiff
don't try pipelining if server closes connections
authorDavid Kalnischkies <david@kalnischkies.de>
Fri, 12 Aug 2016 09:05:58 +0000 (11:05 +0200)
committerJulian Andres Klode <jak@debian.org>
Wed, 5 Oct 2016 19:53:38 +0000 (21:53 +0200)
If a server closes a connection after sending us a file that tends to
mean that its a type of server who always closes the connection – it is
therefore relatively pointless to try pipelining with it even if it
isn't a problem by itself: apt is just restarting the pipeline each
time after it got served one file and the connection is closed.

The problem starts if one or more proxies are between the server and apt
and they disagree about how the connection should be as in the
bugreporters case where the responses apt gets contain both Keep-Alive
and Proxy-Connection headers (which apt both ignores) indicating a
proxy is trying to keep a connection open while the response also
contains "Connection: close" indicating the opposite which apt
understands and respects as it is required to do.

We avoid stepping into this abyss by not performing pipelining anymore
if we got a respond with the indication to close connection if the
response was otherwise a success – error messages are sent by some
servers via this method as their pages tend to be created dynamically
and hence their size isn't known a priori to them.

Closes: #832113
(cherry picked from commit 9714d522056e5256f5a2de587d88eba7cb3291c2)

methods/server.cc

index adc242538b970372f61b3a1b45e96eb01c633283..e260708c5a9180ffc2b52a8b5d81d6ba1d13d908 100644 (file)
@@ -220,8 +220,16 @@ bool ServerState::HeaderLine(string Line)
    if (stringcasecmp(Tag,"Connection:") == 0)
    {
       if (stringcasecmp(Val,"close") == 0)
+      {
         Persistent = false;
-      if (stringcasecmp(Val,"keep-alive") == 0)
+        Pipeline = false;
+        /* Some servers send error pages (as they are dynamically generated)
+           for simplicity via a connection close instead of e.g. chunked,
+           so assuming an always closing server only if we get a file + close */
+        if (Result >= 200 && Result < 300)
+           PipelineAllowed = false;
+      }
+      else if (stringcasecmp(Val,"keep-alive") == 0)
         Persistent = true;
       return true;
    }