-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-122208: Don't delivery PyDict_EVENT_ADDED until it can't fail #122207
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks for the fix! Sorry about the debugging session that I presume must have led to this find :)
@@ -1745,16 +1750,11 @@ insertdict(PyInterpreterState *interp, PyDictObject *mp, | |||
MAINTAIN_TRACKING(mp, key, value); | |||
|
|||
if (ix == DKIX_EMPTY) { | |||
assert(!_PyDict_HasSplitTable(mp)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was it intentional to remove this assertion? Doesn't seem related to the dict watcher stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, thanks for catching that, I'll remove it.
Luckily there was no debugging involved! Just trying to re-factor some existing code to use dict watchers and I was worried about what would happen when the updates would fail (as the existing code handled it). So this will actually make that somewhat cleaner!
Thanks @DinoV for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. |
Summary: Back port of: python/cpython#122207 fixing python/cpython#122208 The current dictionary watchers implementation delivers the added event before it checks to see if we need to re-size the dictionary. This resize can fail so the value isn't added, and then the tracker is out of sync with the true state of the dictionary. This moves the delivery of the event to after any necessary allocations have happened. Reviewed By: jbower-fb Differential Revision: D60182094 fbshipit-source-id: f34940e98ce1caadeee364f9d126d35839661961
Summary: Back port of: python/cpython#122207 fixing python/cpython#122208 The current dictionary watchers implementation delivers the added event before it checks to see if we need to re-size the dictionary. This resize can fail so the value isn't added, and then the tracker is out of sync with the true state of the dictionary. This moves the delivery of the event to after any necessary allocations have happened. Reviewed By: jbower-fb Differential Revision: D60182094 fbshipit-source-id: f34940e98ce1caadeee364f9d126d35839661961
python#122207) Don't delivery PyDict_EVENT_ADDED until it can't fail
python#122207) Don't delivery PyDict_EVENT_ADDED until it can't fail
Currently
PyDict_EVENT_ADDED
can be delivered when the insert is going to fail due to an OOM. This means the listener has no capability of knowing the true state of the dictionary if it fails.This modifies the events to be delivered before the change has happened but only after any underlying necessary allocations have occurred.
added
event before it's guaranteed to be successful leading to possible incosistent state #122208