diff --git a/ChangeLog b/ChangeLog index dcc5568..e9c9b27 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,12 @@ servefile changelog =================== +Unreleased +---------- + + * fixed bug where exception was shown on transmission abort with python3 + + 2020-10-30 v0.5.1 ----------------- diff --git a/servefile/servefile.py b/servefile/servefile.py index 466d0d1..17ed9fa 100755 --- a/servefile/servefile.py +++ b/servefile/servefile.py @@ -714,7 +714,8 @@ class FilePutter(BaseHTTPServer.BaseHTTPRequestHandler): class ThreadedHTTPServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer): 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): diff --git a/tests/test_servefile.py b/tests/test_servefile.py index 1cfdcf9..a18e3af 100644 --- a/tests/test_servefile.py +++ b/tests/test_servefile.py @@ -356,3 +356,24 @@ def test_https_big_download(run_servefile, datadir): urllib3.disable_warnings() 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