python / python/cpython

Heap types implemented in C must have Py_TPFLAGS_HAVE_GC and implement tp_traverse

Offen
#116,946 27 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

extension-modules type-bug
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

If a heap type does not have Py_TPFLAGS_HAVE_GC or doesn't not implement tp_traverse, the garbage collector may fail to collect the type and most of its instances at Python exit. The problem is worse when sub-interpreters are involved: if a sub-interpreter exits and does not clear all of its memory, the other interpreters will continue running with these leaks.

See issue gh-87138 for the rationale.

I wrote an article on the lock type which had this bug and caused a memory leak: https://vstinner.github.io/subinterpreter-leaks.html

Linked PRs
  • gh-116947
  • gh-138290
  • gh-138327
  • gh-138328
  • gh-138331
  • gh-138333
  • gh-138427
  • gh-138428
  • gh-138334
  • gh-138340
  • gh-138341
  • gh-138582
  • gh-138807
  • gh-139073
  • gh-139474
  • gh-141268
  • gh-141448
  • gh-152310
  • gh-156034

The following PRs were directly closed because the types are immutable and empty:

  • gh-138329
  • gh-138330
  • gh-138332

The following PRs were wrongly merged so we reverted them:

  • gh-138266
  • gh-138320
  • gh-138322
  • gh-138288
  • gh-138321
  • gh-138323
  • gh-138289
  • gh-138324
  • gh-138326

PRs for reverting the above commits:

  • gh-138338
  • gh-138337

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit issue gh-87138 und dem verlinkten Artikel über den Lock-Typ; ermittle anschließend die C-Heap-Typen, die von den verlinkten PRs abgedeckt werden. Die Aufgabe ist erledigt, wenn die anwendbaren Heap-Typen Py_TPFLAGS_HAVE_GC und tp_traverse haben und die beschriebenen Leaks beim Beenden des Interpreters und in Subinterpretern behoben sind.

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
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.