Commit 37c6edc2 authored by Jason Madden's avatar Jason Madden

BaseServer and its derived class StreamServer was relying on CPython's reference counting behaviour

to close the socket (or other arguments) when the handler finished. This breaks under PyPy
which uses a different GC.

Fix it by wrapping the handler and explicitly closing the socket when it returns. This fixes test__server
under PyPy, although not in a particularly elegant way. It also negates the need for 57936127.
parent c8f0707e
......@@ -126,11 +126,18 @@ class BaseServer(object):
def do_handle(self, *args):
spawn = self._spawn
handle = self._handle
def _close_when_done(*args):
try:
return handle(*args)
finally:
self.do_close(*args)
try:
if spawn is None:
self._handle(*args)
_close_when_done(*args)
else:
spawn(self._handle, *args)
spawn(_close_when_done, *args)
except:
self.do_close(*args)
raise
......
......@@ -32,9 +32,6 @@ class SimpleStreamServer(StreamServer):
client_socket.sendall('HTTP/1.0 404 WTF?\r\n\r\n')
finally:
fd.close()
# The non-reference count behaviour of PyPy requires
# us to explicitly close this socket or the client never returns
client_socket.close()
class Settings:
ServerClass = StreamServer
......
......@@ -78,7 +78,6 @@ if PYPY:
'test__pywsgi.py',
# No idea!
'test__server.py',
'test_subprocess.py', # test_executable_without_cwd
'FLAKY test___example_servers.py',
]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment