`arraymodule`, `_decimal`: possible lazy import caches reference leaks in free-threaded builds
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug description:
As pointed out by @htjworld in https://github.com/python/cpython/pull/148088#issuecomment-4196296604:
I was wondering about the lazy init pattern in a free-threaded build. If two threads enter
build_struct_timeconcurrently withst->time_struct_time == NULL, both would callPyImport_ImportModuleAttrStringand one overwrite would leave a reference with an incremented refcount that never gets decref'd.
I noticed
arraymodule.cand_decimal.chave the same pattern, so maybe this is just accepted. But _asynciomodule.c initializes eagerly in module_init() which avoids this structurally. Was lazy chosen deliberately here over eager init in init_state()?
While I've addressed this in #148088, I think that this is a valid concern, and import caches should use CAS, just like:
If there's interest, I can do it.
(It seems similar to #149000, so perhaps a more thorough check warranted.)
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, die verzögerte Initialisierung in arraymodule.c und _decimal.c mit der eifrigen Initialisierung in _asynciomodule.c und dem CAS-Muster in Modules/_sre/sre.c zu vergleichen. Prüfe die Free-Threaded-Pfade auf konkurrierende Initialisierung und Referenzlecks; als erledigt gilt die Aufgabe, wenn die betroffenen Import-Caches unter diesem Nebenläufigkeitsmuster sicher sind und das relevante Verhalten durch Validierung abgedeckt ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- c, python
- Bereich
- backend
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 48/100