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

Fix ListenerHandler race condition #1495

Merged
merged 3 commits into from
Sep 6, 2021

Conversation

mdickinson
Copy link
Member

Fixes #1494.

I've added a couple of unit tests for ListenerHandler, testing the two main use-cases (methods and functions as handlers). I don't have a regression test for the race condition - the race condition exists, but is almost impossible to reproduce programmatically.

@@ -1195,22 +1195,15 @@ def owner_deleted(self, ref):

class ListenerHandler(object):
def __init__(self, handler):
if type(handler) is MethodType:
object = handler.__self__
if object is not None:
Copy link
Member Author

Choose a reason for hiding this comment

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

In Python 3, there's no normal situation where handler can be an instance of MethodType and handler.__self__ can be None, so I've removed this branch. (This code is likely a leftover from Python 2, where this branch catches unbound methods.)

@@ -1195,22 +1195,15 @@ def owner_deleted(self, ref):

class ListenerHandler(object):
def __init__(self, handler):
if type(handler) is MethodType:
Copy link
Member Author

Choose a reason for hiding this comment

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

I can't see a good reason to do an exact type check rather than the usual isinstance check here.

@mdickinson mdickinson merged commit da44418 into main Sep 6, 2021
@mdickinson mdickinson deleted the fix/listener-handler-race-condition branch September 6, 2021 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Race condition in ListenerHandler.__call__
2 participants