GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||
GeezerVison is showing github.com — gh-127716: Fix data race in `memoryview.release()` by weixlu · Pull Request #154770 · python/cpython Conversation
|
| step | thread A | thread B |
|---|---|---|
| test flag (1) | sees not released → continues | sees not released → continues |
| set flag (2) | sets RELEASED |
sets RELEASED (again, no-op) |
| decrement (3) | --exports → 0, calls mbuf_release() |
--exports → -1 |
Both threads get past the guard, so both run the decrement. As a result, mbuf->exports drops below 0.
To fix this, we have to make self->flags's test-and-set a single atomic operation, so that exactly one thread wins the transition and performs the decrement. Here I'm using _Py_atomic_or_uint32. It is used in both release entry points:
_memory_release() — This code path belongs to the case "Debug build with ASan" in the original issue.mbuf_release() — This code path belongs to the case "Plain debug build (no ASan)"python -m test test_memoryview passes (with and without GIL).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This would need a fair amount of work before it's ready to merge:
GH-155882 fixes the missing atomics on the export increments but doesn't fix the last issue. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This will be fix in #156248 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.