asyncio: Fix ProactorEventLoop.start_serving_pipe()
If a client connected before the server was closed: drop the client (close the pipe) and exit.
This commit is contained in:
parent
b76bcc4ffc
commit
a19b7b3fca
|
@ -257,7 +257,7 @@ class PipeServer(object):
|
||||||
|
|
||||||
def _server_pipe_handle(self, first):
|
def _server_pipe_handle(self, first):
|
||||||
# Return a wrapper for a new pipe handle.
|
# Return a wrapper for a new pipe handle.
|
||||||
if self._address is None:
|
if self.closed():
|
||||||
return None
|
return None
|
||||||
flags = _winapi.PIPE_ACCESS_DUPLEX | _winapi.FILE_FLAG_OVERLAPPED
|
flags = _winapi.PIPE_ACCESS_DUPLEX | _winapi.FILE_FLAG_OVERLAPPED
|
||||||
if first:
|
if first:
|
||||||
|
@ -273,6 +273,9 @@ class PipeServer(object):
|
||||||
self._free_instances.add(pipe)
|
self._free_instances.add(pipe)
|
||||||
return pipe
|
return pipe
|
||||||
|
|
||||||
|
def closed(self):
|
||||||
|
return (self._address is None)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
if self._accept_pipe_future is not None:
|
if self._accept_pipe_future is not None:
|
||||||
self._accept_pipe_future.cancel()
|
self._accept_pipe_future.cancel()
|
||||||
|
@ -325,12 +328,21 @@ class ProactorEventLoop(proactor_events.BaseProactorEventLoop):
|
||||||
if f:
|
if f:
|
||||||
pipe = f.result()
|
pipe = f.result()
|
||||||
server._free_instances.discard(pipe)
|
server._free_instances.discard(pipe)
|
||||||
|
|
||||||
|
if server.closed():
|
||||||
|
# A client connected before the server was closed:
|
||||||
|
# drop the client (close the pipe) and exit
|
||||||
|
pipe.close()
|
||||||
|
return
|
||||||
|
|
||||||
protocol = protocol_factory()
|
protocol = protocol_factory()
|
||||||
self._make_duplex_pipe_transport(
|
self._make_duplex_pipe_transport(
|
||||||
pipe, protocol, extra={'addr': address})
|
pipe, protocol, extra={'addr': address})
|
||||||
|
|
||||||
pipe = server._get_unconnected_pipe()
|
pipe = server._get_unconnected_pipe()
|
||||||
if pipe is None:
|
if pipe is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
f = self._proactor.accept_pipe(pipe)
|
f = self._proactor.accept_pipe(pipe)
|
||||||
except OSError as exc:
|
except OSError as exc:
|
||||||
if pipe and pipe.fileno() != -1:
|
if pipe and pipe.fileno() != -1:
|
||||||
|
|
Loading…
Reference in New Issue