From 89b79e4b7f895576ef1393eaa9f74432d93b299e Mon Sep 17 00:00:00 2001 From: bendikro Date: Thu, 25 May 2023 14:32:37 +0200 Subject: [PATCH] [Core] Fix bug when emiting event in EventManager In some cases, when emiting events with EventManager.emit_event(), the underlying dictionary of interested sessions can change during iteration, causing: RuntimeError: dictionary changed size during iteration Fix by iterating over a copy of the dictionary. Closes: https://dev.deluge-torrent.org/ticket/3351 Closes: https://github.com/deluge-torrent/deluge/pull/425 --- deluge/core/rpcserver.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deluge/core/rpcserver.py b/deluge/core/rpcserver.py index d4ca5d19d..81ab2e0a5 100644 --- a/deluge/core/rpcserver.py +++ b/deluge/core/rpcserver.py @@ -545,8 +545,8 @@ class RPCServer(component.Component): :type event: :class:`deluge.event.DelugeEvent` """ log.debug('intevents: %s', self.factory.interested_events) - # Find sessions interested in this event - for session_id, interest in self.factory.interested_events.items(): + # Use copy of `interested_events` since it can mutate while iterating. + for session_id, interest in self.factory.interested_events.copy().items(): if event.name in interest: log.debug('Emit Event: %s %s', event.name, event.args) # This session is interested so send a RPC_EVENT