From 3fc60cb312a74f2340e0c712bc799bda6df82c44 Mon Sep 17 00:00:00 2001 From: mhchia Date: Tue, 4 Feb 2020 17:04:28 +0800 Subject: [PATCH] SwarmConn: iterate `streams.copy` in `_cleanup` To avoid `RuntimeError` if `streams` is changed. --- libp2p/network/connection/swarm_connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libp2p/network/connection/swarm_connection.py b/libp2p/network/connection/swarm_connection.py index a5e22e7..0e930f5 100644 --- a/libp2p/network/connection/swarm_connection.py +++ b/libp2p/network/connection/swarm_connection.py @@ -46,7 +46,7 @@ class SwarmConn(INetConn): # This is just for cleaning up state. The connection has already been closed. # We *could* optimize this but it really isn't worth it. - for stream in self.streams: + for stream in self.streams.copy(): await stream.reset() # Force context switch for stream handlers to process the stream reset event we just emit # before we cancel the stream handler tasks.