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:
parent
c0ab609559
commit
13930ae718
|
@ -61,12 +61,11 @@ class SwarmConn(INetConn):
|
||||||
try:
|
try:
|
||||||
stream = await self.muxed_conn.accept_stream()
|
stream = await self.muxed_conn.accept_stream()
|
||||||
except MuxedConnUnavailable:
|
except MuxedConnUnavailable:
|
||||||
|
await self.close()
|
||||||
break
|
break
|
||||||
# Asynchronously handle the accepted stream, to avoid blocking the next stream.
|
# Asynchronously handle the accepted stream, to avoid blocking the next stream.
|
||||||
nursery.start_soon(self._handle_muxed_stream, stream)
|
nursery.start_soon(self._handle_muxed_stream, stream)
|
||||||
|
|
||||||
await self.close()
|
|
||||||
|
|
||||||
async def _handle_muxed_stream(self, muxed_stream: IMuxedStream) -> None:
|
async def _handle_muxed_stream(self, muxed_stream: IMuxedStream) -> None:
|
||||||
net_stream = self._add_stream(muxed_stream)
|
net_stream = self._add_stream(muxed_stream)
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user