[New-bugs-announce] [issue37261] test_io leaks references on AMD64 Fedora Rawhide Refleaks 3.8

STINNER Victor report at bugs.python.org
Wed Jun 12 21:43:10 EDT 2019


New submission from STINNER Victor <vstinner at redhat.com>:

test_io leaks references on AMD64 Fedora Rawhide Refleaks 3.8:
https://buildbot.python.org/all/#/builders/229/builds/10

test_io leaked [23208, 23204, 23208] references, sum=69620
test_io leaked [7657, 7655, 7657] memory blocks, sum=22969


The issue has been introduced by my change:

commit c15a682603a47f5aef5025f6a2e3babb699273d6
Author: Victor Stinner <vstinner at redhat.com>
Date:   Thu Jun 13 00:23:49 2019 +0200

    bpo-37223: test_io: silence destructor errors (GH-14031)
    
    * bpo-18748: Fix _pyio.IOBase destructor (closed case) (GH-13952)
    
    _pyio.IOBase destructor now does nothing if getting the closed
    attribute fails to better mimick _io.IOBase finalizer.
    
    (cherry picked from commit 4f6f7c5a611905fb6b81671547f268c226bc646a)
    
    * bpo-37223: test_io: silence destructor errors (GH-13954)
    
    Implement also MockNonBlockWriterIO.seek() method.
    
    (cherry picked from commit b589cef9c4dada2fb84ce0fae5040ecf16d9d5ef)
    
    * bpo-37223, test_io: silence last 'Exception ignored in:' (GH-14029)
    
    Use catch_unraisable_exception() to ignore 'Exception ignored in:'
    error when the internal BufferedWriter of the BufferedRWPair is
    destroyed. The C implementation doesn't give access to the
    internal BufferedWriter, so just ignore the warning instead.
    
    (cherry picked from commit 913fa1c8245d1cde6edb4254f4fb965cc91786ef)


It seems like the root issue is the usage of catch_unraisable_exception() in test_io.

class catch_unraisable_exception:
    def __init__(self):
        self.unraisable = None
        self._old_hook = None

    def _hook(self, unraisable):
        self.unraisable = unraisable

    def __enter__(self):
        self._old_hook = sys.unraisablehook
        sys.unraisablehook = self._hook
        return self

    def __exit__(self, *exc_info):
        # Clear the unraisable exception to explicitly break a reference cycle
        del self.unraisable
        sys.unraisablehook = self._old_hook

*Sometimes* "del self.unraisable" of __exit__() triggers a new unraisable exception which calls again the _hook() method which sets again the unraisable attribute.

catch_unraisable_exception resurects _io.BufferedWriter objects, and then "del self.unraisable" calls again their finalizer: iobase_finalize() is called again, and iobase_finalize() calls PyErr_WriteUnraisable() on close() failure.

----------
messages: 345449
nosy: vstinner
priority: normal
severity: normal
status: open
title: test_io leaks references on AMD64 Fedora Rawhide Refleaks 3.8
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37261>
_______________________________________


More information about the New-bugs-announce mailing list