Skip to content

Commit

Permalink
[Core] Fix bug when emiting event in EventManager
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bendikro committed May 25, 2023
1 parent 366cded commit 64c5236
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion deluge/core/rpcserver.py
Expand Up @@ -546,7 +546,9 @@ def emit_event(self, event):
"""
log.debug('intevents: %s', self.factory.interested_events)
# Find sessions interested in this event
for session_id, interest in self.factory.interested_events.items():
# The interested_events dict can change while iterating,
# therefore we need to iterate over a copy
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
Expand Down

0 comments on commit 64c5236

Please sign in to comment.