server: always close http socket if responding with an error (issue6033) stable 4.8.2
authorAugie Fackler <raf@durin42.com>
Sun, 06 Jan 2019 14:58:54 -0500
branchstable
changeset 41023 197f092b2cd9
parent 41022 481249481392
child 41127 7354292899eb
server: always close http socket if responding with an error (issue6033) It's possible for hgweb to respond _very_ early with an error if we're catching certain types of errors. When we do, we need to tell the client the socket is toast when there's a POST involved because otherwise there can be lingering POST data on the socket that will confuse any future requests on the socket. This manifested as a flaky failure on Linux in an lfs extension test and a reliable failure on FreeBSD. With this patch applied, test-lfs-serve-access.t now passes for me on FreeBSD. Differential Revision: https://phab.mercurial-scm.org/D5498
mercurial/hgweb/server.py
--- a/mercurial/hgweb/server.py	Sat Jan 05 15:44:55 2019 +0900
+++ b/mercurial/hgweb/server.py	Sun Jan 06 14:58:54 2019 -0500
@@ -127,6 +127,13 @@
             and not path.startswith(self.server.prefix + b'/')):
             self._start_response(pycompat.strurl(common.statusmessage(404)),
                                  [])
+            if self.command == 'POST':
+                # Paranoia: tell the client we're going to close the
+                # socket so they don't try and reuse a socket that
+                # might have a POST body waiting to confuse us. We do
+                # this by directly munging self.saved_headers because
+                # self._start_response ignores Connection headers.
+                self.saved_headers = [(r'Connection', r'Close')]
             self._write(b"Not Found")
             self._done()
             return