python / python/cpython

`atexit` module breaks refleak check

Ouverte
#139,289 5 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

extension-modules tests type-bug
Langage dominant
Python
Étoiles
77.2k
Forks
35.9k
Métriques de merge des PR
Métriques de PR en attente

Description

Bug report

Bug description:

If the test registers a callback with atexit module, refleak test will consider it a leak.

    def test_refleak(self):
        atexit.register(lambda: None)

This is the root cause of the buildbot failure of https://github.com/python/cpython/pull/139185. It's a couple of coincidences that caused the seemingly unrelated issue. Basically, clearing the module cache in test_zipimport made the module-level code in rlcompleter, which includes a register to atexit, run more than once.

There are a few possible approaches to fix this, but I did not find the solution that I'm immediately happy with.

I consider this a test framework bug as this should be a valid behavior. The ideal solution is to keep the atexit callbacks before running test in a loop and restore it after. However, atexit does not provide such an interface, public or private. You can either clear it or run it. The callbacks are stored in a state of the interpreter and we don't have any access to it.

Without that, we either need to somehow calculate the allocated memory by atexit, or hope that no one writes a test that writes to atexit. Of course there might be other ways that I did not think of.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs
  • gh-139305
  • gh-139357
  • [3.14] gh-139305 was backported as part of gh-139280

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par le framework de test refleak et l’exemple test_refleak qui enregistre un callback atexit. Examinez comment la suppression du cache des modules par test_zipimport entraîne l’exécution répétée de l’enregistrement au niveau du module de rlcompleter, et consultez les PRs associés gh-139305 et gh-139357 pour examiner le travail existant. Le travail est terminé lorsque les enregistrements atexit valides n’apparaissent plus comme des refleaks.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
testing-qa
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
20/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.