SwarmConn: perform close right away

In `_handle_new_streams`, when the underlying muxed conn is unavailable,
close `SwarmConn` itself right away, to reset all the streams.
Therefore, the stream processed by `_handle_muxed_stream` are conscious
of the fact that they are reset. It allows a more graceful clean up.
This commit is contained in:
mhchia 2020-02-04 22:51:21 +08:00
parent c0ab609559
commit 13930ae718
No known key found for this signature in database
GPG Key ID: 389EFBEA1362589A

View File

@ -61,12 +61,11 @@ class SwarmConn(INetConn):
try:
stream = await self.muxed_conn.accept_stream()
except MuxedConnUnavailable:
await self.close()
break
# Asynchronously handle the accepted stream, to avoid blocking the next stream.
nursery.start_soon(self._handle_muxed_stream, stream)
await self.close()
async def _handle_muxed_stream(self, muxed_stream: IMuxedStream) -> None:
net_stream = self._add_stream(muxed_stream)
try: