comparison mercurial/hgweb/server.py @ 52152:891f6d56f3db stable

hgweb: skip logging ConnectionAbortedError Not stacktracing on `ConnectionResetError` was added in 6bbb12cba5a8 (though it was spelled differently for py2 support), but for some reason Windows occasionally triggers a `ConnectionAbortedError` here across various *.t files (notably `test-archive.t` and `test-lfs-serve-access.t`, but there are others). The payload that fails to send seems to be the html that describes the error to the client, so I suspect some code is seeing the error status code and closing the connection before the server gets to write this html. So don't log it, for test stability- nothing we can do anyway. FWIW, the CPython implementation of wsgihander specifically ignores these two errors, plus `BrokenPipeError`, with a comment that "we expect the client to close the connection abruptly from time to time"[1]. The `BrokenPipeError` is swallowed a level up in `do_write()`, and avoids writing the response following this stacktrace. I'm puzzled why a response is being written after these connection errors are detected- the CPython code referenced doesn't, and the connection is now broken at this point. Perhaps these errors should both be handled with the `BrokenPipeError` after the freeze. (The refactoring away from py2 compat may not be desireable in the freeze, but this is much easier to read, and obviously correct given the referenced CPython code.) I suspect this is what 6bceecb28806 was attempting to fix, but it wasn't specific about the sporadic errors it was seeing. [1] https://github.com/python/cpython/blob/b2eaa75b176e07730215d76d8dce4d63fb493391/Lib/wsgiref/handlers.py#L139
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 31 Oct 2024 17:24:18 -0400
parents f4733654f144
children c9baa3541b20
comparison
equal deleted inserted replaced
52151:8766d47edfd1 52152:891f6d56f3db
6 # This software may be used and distributed according to the terms of the 6 # This software may be used and distributed according to the terms of the
7 # GNU General Public License version 2 or any later version. 7 # GNU General Public License version 2 or any later version.
8 8
9 from __future__ import annotations 9 from __future__ import annotations
10 10
11 import errno
12 import os 11 import os
13 import socket 12 import socket
14 import sys 13 import sys
15 import traceback 14 import traceback
16 import wsgiref.validate 15 import wsgiref.validate
122 self.do_write() 121 self.do_write()
123 except Exception as e: 122 except Exception as e:
124 # I/O below could raise another exception. So log the original 123 # I/O below could raise another exception. So log the original
125 # exception first to ensure it is recorded. 124 # exception first to ensure it is recorded.
126 if not ( 125 if not (
127 isinstance(e, (OSError, socket.error)) 126 isinstance(e, (ConnectionResetError, ConnectionAbortedError))
128 and e.errno == errno.ECONNRESET
129 ): 127 ):
130 tb = "".join(traceback.format_exception(*sys.exc_info())) 128 tb = "".join(traceback.format_exception(*sys.exc_info()))
131 # We need a native-string newline to poke in the log 129 # We need a native-string newline to poke in the log
132 # message, because we won't get a newline when using an 130 # message, because we won't get a newline when using an
133 # r-string. This is the easy way out. 131 # r-string. This is the easy way out.