[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
This commit is contained in:
bendikro 2023-05-25 14:32:37 +02:00 committed by Calum Lind
parent e70e43e631
commit 89b79e4b7f
No known key found for this signature in database
GPG Key ID: 90597A687B836BA3
1 changed files with 2 additions and 2 deletions

View File

@ -545,8 +545,8 @@ class RPCServer(component.Component):
:type event: :class:`deluge.event.DelugeEvent` :type event: :class:`deluge.event.DelugeEvent`
""" """
log.debug('intevents: %s', self.factory.interested_events) log.debug('intevents: %s', self.factory.interested_events)
# Find sessions interested in this event # Use copy of `interested_events` since it can mutate while iterating.
for session_id, interest in self.factory.interested_events.items(): for session_id, interest in self.factory.interested_events.copy().items():
if event.name in interest: if event.name in interest:
log.debug('Emit Event: %s %s', event.name, event.args) log.debug('Emit Event: %s %s', event.name, event.args)
# This session is interested so send a RPC_EVENT # This session is interested so send a RPC_EVENT