Fix exception on transmission abort with python3

With python3 sys.exc_value does no longer exist, but we can replace it
with sys.exc_info().
This commit is contained in:
Sebastian Lohff 2020-11-25 02:56:35 +01:00
parent 11a7d8bd13
commit 058de2f39c
3 changed files with 29 additions and 1 deletions

View File

@ -2,6 +2,12 @@ servefile changelog
=================== ===================
Unreleased
----------
* fixed bug where exception was shown on transmission abort with python3
2020-10-30 v0.5.1 2020-10-30 v0.5.1
----------------- -----------------

View File

@ -714,7 +714,8 @@ class FilePutter(BaseHTTPServer.BaseHTTPRequestHandler):
class ThreadedHTTPServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer): class ThreadedHTTPServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer):
def handle_error(self, request, client_address): def handle_error(self, request, client_address):
print("%s ABORTED transmission (Reason: %s)" % (client_address[0], sys.exc_value)) _, exc_value, _ = sys.exc_info()
print("%s ABORTED transmission (Reason: %s)" % (client_address[0], exc_value))
def catchSSLErrors(BaseSSLClass): def catchSSLErrors(BaseSSLClass):

View File

@ -356,3 +356,24 @@ def test_https_big_download(run_servefile, datadir):
urllib3.disable_warnings() urllib3.disable_warnings()
check_download(data, protocol='https', verify=False) check_download(data, protocol='https', verify=False)
def test_abort_download(run_servefile, datadir):
data = "x" * (10 * 1024 ** 2)
p = datadir({'testfile': data}) / 'testfile'
env = os.environ.copy()
env['PYTHONUNBUFFERED'] = '1'
proc = run_servefile(str(p), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env)
# provoke a connection abort
# hopefully the buffers will not fill up with all of the 10mb
sock = socket.socket(socket.AF_INET)
sock.connect(("localhost", 8080))
sock.send(b"GET /testfile HTTP/1.0\n\n")
resp = sock.recv(100)
assert resp != b''
sock.close()
time.sleep(0.1)
proc.kill()
out = proc.stdout.read().decode()
assert "127.0.0.1 ABORTED transmission" in out