Mercurial > hg
changeset 41479:6bbb12cba5a8
server: skip logging of ECONNRESET
I believe this was exposed by 5492dc20, because the sending of the 500
would have already failed and prevented this logging. On Python 3,
this will be a ConnectionResetError, which is a subtype of OSError,
which is why we check for both OSError and socket.error.
Bonus: this fixes a race in test-hgweb.t where sometimes the
ECONNRESET wouldn't happen, because now we just don't log those
errors.
Differential Revision: https://phab.mercurial-scm.org/D5764
author | Augie Fackler <augie@google.com> |
---|---|
date | Wed, 30 Jan 2019 17:24:57 -0500 |
parents | 8e0dd36f7a97 |
children | eb6700e6c5ea |
files | mercurial/hgweb/server.py tests/test-hgweb.t |
diffstat | 2 files changed, 10 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/hgweb/server.py Wed Jan 30 18:32:11 2019 -0500 +++ b/mercurial/hgweb/server.py Wed Jan 30 17:24:57 2019 -0500 @@ -100,16 +100,18 @@ def do_POST(self): try: self.do_write() - except Exception: + except Exception as e: # I/O below could raise another exception. So log the original # exception first to ensure it is recorded. - tb = r"".join(traceback.format_exception(*sys.exc_info())) - # We need a native-string newline to poke in the log - # message, because we won't get a newline when using an - # r-string. This is the easy way out. - newline = chr(10) - self.log_error(r"Exception happened during processing " - r"request '%s':%s%s", self.path, newline, tb) + if not (isinstance(e, (OSError, socket.error)) + and e.errno == errno.ECONNRESET): + tb = r"".join(traceback.format_exception(*sys.exc_info())) + # We need a native-string newline to poke in the log + # message, because we won't get a newline when using an + # r-string. This is the easy way out. + newline = chr(10) + self.log_error(r"Exception happened during processing " + r"request '%s':%s%s", self.path, newline, tb) self._start_response(r"500 Internal Server Error", []) self._write(b"Internal Server Error")
--- a/tests/test-hgweb.t Wed Jan 30 18:32:11 2019 -0500 +++ b/tests/test-hgweb.t Wed Jan 30 17:24:57 2019 -0500 @@ -911,18 +911,6 @@ errors $ cat errors.log | "$PYTHON" $TESTDIR/filtertraceback.py - $LOCALIP - - [$ERRDATE$] Exception happened during processing request '/?cmd=spam': (glob) - Traceback (most recent call last): - error: [Errno 104] $ECONNRESET$ - - $LOCALIP - - [$ERRDATE$] Exception happened during processing request '/spam': (glob) - Traceback (most recent call last): - error: [Errno 104] $ECONNRESET$ - - $LOCALIP - - [$ERRDATE$] Exception happened during processing request '/spam/tip/foo': (glob) - Traceback (most recent call last): - error: [Errno 104] $ECONNRESET$ - $ rm -f errors.log Uncaught exceptions result in a logged error and canned HTTP response