Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Fix bug when emiting event in EventManager #425

Closed
wants to merge 1 commit into from

Conversation

bendikro
Copy link
Member

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

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():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel the comment is redundant since the commit message explains the reasoning

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the commit message is to explain why the change is needed. The comment is to ensure nobody removes the copy part later on because "It doesn't seem necessary".

Copy link
Member

@cas-- cas-- May 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a reasonable point, okay let's remove original redundant comment and make the new comment a short one-liner:

-        # 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
+        # Use copy of `interested_events` since it can mutate while iterating.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I commit and rebase?

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants