Skip to content

_pyio.BytesIO destructor raises an unraisable exception if there is a BytesIO buffer #111330

Open
@serhiy-storchaka

Description

@serhiy-storchaka

Bug report

The following code

from _pyio import BytesIO
memio = BytesIO(b"1234567890")
buf = memio.getbuffer()
del memio

raises an unraisable exception:

Exception ignored in: <function IOBase.__del__ at 0x7f390c69b410>
Traceback (most recent call last):
  File "/home/serhiy/py/cpython/Lib/_pyio.py", line 418, in __del__
    self.close()
  File "/home/serhiy/py/cpython/Lib/_pyio.py", line 907, in close
    self._buffer.clear()
BufferError: Existing exports of data: object cannot be re-sized

Deleting a reference to object while there is still a live buffer that refers its content should not be an issue. It is not an abnormal situation and it should not produce any output.

It is only for the Python implementation. The C implementation raises an unraisable exception in different situation. See #111331.

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixes3.12only security fixes3.13bugs and security fixesstdlibPython modules in the Lib dirtopic-IOtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions