From 4a689c7d57d436d7e562b3c73b8bc2446fd37b99 Mon Sep 17 00:00:00 2001 From: mhchia Date: Sat, 14 Sep 2019 14:57:43 +0800 Subject: [PATCH] Fix error when reset If `Mplex` is cleanup first, `MplexStream.reset` possibly fails because `Mplex.streams` is set to `None` in `cleanup`. --- libp2p/stream_muxer/mplex/mplex_stream.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libp2p/stream_muxer/mplex/mplex_stream.py b/libp2p/stream_muxer/mplex/mplex_stream.py index 87b039f..8cabccc 100644 --- a/libp2p/stream_muxer/mplex/mplex_stream.py +++ b/libp2p/stream_muxer/mplex/mplex_stream.py @@ -204,7 +204,11 @@ class MplexStream(IMuxedStream): self.event_remote_closed.set() async with self.mplex_conn.streams_lock: - del self.mplex_conn.streams[self.stream_id] + if ( + self.mplex_conn.streams is not None + and self.stream_id in self.mplex_conn.streams + ): + del self.mplex_conn.streams[self.stream_id] # TODO deadline not in use def set_deadline(self, ttl: int) -> bool: