René's URL Explorer Experiment


Title: Segfault/abort from calling `BytesIO` `unshare_buffer` in threads on a free-threaded build · Issue #132551 · python/cpython · GitHub

Open Graph Title: Segfault/abort from calling `BytesIO` `unshare_buffer` in threads on a free-threaded build · Issue #132551 · python/cpython

X Title: Segfault/abort from calling `BytesIO` `unshare_buffer` in threads on a free-threaded build · Issue #132551 · python/cpython

Description: Crash report What happened? This seems to be almost the same issue as #111174, but for free-threaded builds. In a free-threaded build it's possible to segfault (rare on debug build) or abort (common on debug build) the interpreter with t...

Open Graph Description: Crash report What happened? This seems to be almost the same issue as #111174, but for free-threaded builds. In a free-threaded build it's possible to segfault (rare on debug build) or abort (commo...

X Description: Crash report What happened? This seems to be almost the same issue as #111174, but for free-threaded builds. In a free-threaded build it's possible to segfault (rare on debug build) or abort (c...

Opengraph URL: https://github.com/python/cpython/issues/132551

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Segfault/abort from calling `BytesIO` `unshare_buffer` in threads on a free-threaded build","articleBody":"# Crash report\n\n### What happened?\n\nThis seems to be almost the same issue as https://github.com/python/cpython/issues/111174, but for free-threaded builds.\n\nIn a free-threaded build it's possible to segfault (rare on debug build) or abort (common on debug build) the interpreter with the following code (which might not be minimal, I'll try to reduce it further later today):\n\n```python\nfrom io import BytesIO\nfrom threading import Thread\nfrom time import sleep\n\n\ndef call_getbuffer(obj: BytesIO) -\u003e None:\n    obj.getvalue()\n    obj.getbuffer()\n    obj.getbuffer()\n    sleep(0.001)\n    obj.getbuffer()\n    obj.getbuffer()\n    obj.getbuffer()\n    sleep(0.006)\n    obj.getbuffer()\n    obj.getvalue()\n\nfor x in range(100):\n    alive = []\n\n    obj = BytesIO()\n    for x in range(50):\n        alive.append(Thread(target=call_getbuffer, args=(obj,)))\n        alive.append(Thread(target=call_getbuffer, args=(obj,)))\n        alive.append(Thread(target=call_getbuffer, args=(obj,)))\n\n    alive.append(Thread(target=obj.__exit__, args=(None, None, None)))\n    alive.append(Thread(target=call_getbuffer, args=(obj,)))\n    alive.append(Thread(target=call_getbuffer, args=(obj,)))\n    alive.append(Thread(target=call_getbuffer, args=(obj,)))\n\n    for t in alive:\n        t.start()\n    for t in alive:\n        t.join()\n```\n\nSegfault backtrace 1 (gcc, release):\n```\nThread 613 \"Thread-612 (cal\" received signal SIGSEGV, Segmentation fault.\n\nbytesiobuf_getbuffer (op=0x48ec60f00f0, view=0x48ec61101b0, flags=284) at ./Modules/_io/bytesio.c:1090\n1090        if (b-\u003eexports == 0 \u0026\u0026 SHARED_BUF(b)) {\n\n#0  bytesiobuf_getbuffer (op=0x48ec60f00f0, view=0x48ec61101b0, flags=284) at ./Modules/_io/bytesio.c:1090\n#1  0x00005555556c6519 in _PyManagedBuffer_FromObject (flags=284, base=0x48ec60f00f0)\n    at Objects/memoryobject.c:97\n#2  PyMemoryView_FromObjectAndFlags (flags=284, v=0x48ec60f00f0) at Objects/memoryobject.c:813\n#3  PyMemoryView_FromObject (v=v@entry=0x48ec60f00f0) at Objects/memoryobject.c:856\n#4  0x00005555558b98bf in _io_BytesIO_getbuffer_impl (cls=\u003coptimized out\u003e, self=0x48ebe9f8020)\n    at ./Modules/_io/bytesio.c:337\n#5  _io_BytesIO_getbuffer (self=0x48ebe9f8020, cls=\u003coptimized out\u003e, args=\u003coptimized out\u003e,\n    nargs=\u003coptimized out\u003e, kwnames=\u003coptimized out\u003e) at ./Modules/_io/clinic/bytesio.c.h:103\n#6  0x0000555555652cb7 in _PyObject_VectorcallTstate (kwnames=\u003coptimized out\u003e, nargsf=\u003coptimized out\u003e,\n    args=\u003coptimized out\u003e, callable=0x48ebe3e6ae0, tstate=0x555555c0bb70)\n    at ./Include/internal/pycore_call.h:169\n#7  PyObject_Vectorcall (callable=0x48ebe3e6ae0, args=\u003coptimized out\u003e, nargsf=\u003coptimized out\u003e,\n    kwnames=\u003coptimized out\u003e) at Objects/call.c:327\n#8  0x00005555555e9486 in _PyEval_EvalFrameDefault (tstate=\u003coptimized out\u003e, frame=\u003coptimized out\u003e,\n    throwflag=\u003coptimized out\u003e) at Python/generated_cases.c.h:3850\n#9  0x00005555557d01de in _PyEval_EvalFrame (throwflag=0, frame=\u003coptimized out\u003e, tstate=0x555555c0bb70)\n    at ./Include/internal/pycore_ceval.h:119\n#10 _PyEval_Vector (tstate=0x555555c0bb70, func=0x48ebe713f00, locals=0x0, args=0x7fff85791958,\n    argcount=\u003coptimized out\u003e, kwnames=\u003coptimized out\u003e) at Python/ceval.c:1913\n#11 0x0000555555656b23 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=1, args=0x7fff85791958,\n    callable=0x48ebe713f00, tstate=0x555555c0bb70) at ./Include/internal/pycore_call.h:169\n#12 method_vectorcall (method=\u003coptimized out\u003e, args=0x7fff85791c68, nargsf=\u003coptimized out\u003e, kwnames=0x0)\n    at Objects/classobject.c:72\n#13 0x00005555557eeac6 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=0, args=0x7fff85791c68,\n    callable=0x48ec60d0100, tstate=0x555555c0bb70) at ./Include/internal/pycore_call.h:169\n#14 context_run (self=0x48ebea12fc0, args=\u003coptimized out\u003e, nargs=\u003coptimized out\u003e, kwnames=\u003coptimized out\u003e)\n    at Python/context.c:728\n#15 0x00005555555ee959 in _PyEval_EvalFrameDefault (tstate=\u003coptimized out\u003e, frame=\u003coptimized out\u003e,\n    throwflag=\u003coptimized out\u003e) at Python/generated_cases.c.h:3521\n#16 0x00005555557d01de in _PyEval_EvalFrame (throwflag=0, frame=\u003coptimized out\u003e, tstate=0x555555c0bb70)\n    at ./Include/internal/pycore_ceval.h:119\n#17 _PyEval_Vector (tstate=0x555555c0bb70, func=0x48ebe713fc0, locals=0x0, args=0x7fff85791da8,\n    argcount=\u003coptimized out\u003e, kwnames=\u003coptimized out\u003e) at Python/ceval.c:1913\n#18 0x0000555555656b23 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=1, args=0x7fff85791da8,\n    callable=0x48ebe713fc0, tstate=0x555555c0bb70) at ./Include/internal/pycore_call.h:169\n#19 method_vectorcall (method=\u003coptimized out\u003e, args=0x555555b41890 \u003c_PyRuntime+114512\u003e,\n    nargsf=\u003coptimized out\u003e, kwnames=0x0) at Objects/classobject.c:72\n#20 0x00005555558f0221 in thread_run (boot_raw=0x555555c07040) at ./Modules/_threadmodule.c:353\n#21 0x000055555586c03b in pythread_wrapper (arg=\u003coptimized out\u003e) at Python/thread_pthread.h:242\n#22 0x00007ffff7d32ac3 in start_thread (arg=\u003coptimized out\u003e) at ./nptl/pthread_create.c:442\n#23 0x00007ffff7dc4850 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81\n```\n\nSegfault backtrace 2 (clang, debug, ASAN):\n```\nThread 457 \"Thread-456 (cal\" received signal SIGSEGV, Segmentation fault.\n[Switching to Thread 0x7fff5f1af640 (LWP 1109867)]\nPyBytes_AS_STRING (op=0x0) at ./Include/cpython/bytesobject.h:25\n25          return _PyBytes_CAST(op)-\u003eob_sval;\n\n#0  PyBytes_AS_STRING (op=0x0) at ./Include/cpython/bytesobject.h:25\n#1  bytesiobuf_getbuffer (op=op@entry=\u003c_io._BytesIOBuffer at remote 0x7fffba0e01f0\u003e, view=\u003coptimized out\u003e,\n    flags=284) at ./Modules/_io/bytesio.c:1097\n#2  0x00005555559dfed1 in PyObject_GetBuffer (obj=obj@entry=\u003c_io._BytesIOBuffer at remote 0x7fffba0e01f0\u003e,\n    view=view@entry=0x7fffba170400, flags=0, flags@entry=284) at Objects/abstract.c:445\n#3  0x0000555555b69e59 in _PyManagedBuffer_FromObject (\n    base=base@entry=\u003c_io._BytesIOBuffer at remote 0x7fffba0e01f0\u003e, flags=flags@entry=284)\n    at Objects/memoryobject.c:97\n#4  0x0000555555b65759 in PyMemoryView_FromObjectAndFlags (\n    v=\u003c_io._BytesIOBuffer at remote 0x7fffba0e01f0\u003e, flags=284) at Objects/memoryobject.c:813\n#5  0x0000555556091f8d in _io_BytesIO_getbuffer_impl (self=0x7fffb4afccd0, cls=\u003coptimized out\u003e)\n    at ./Modules/_io/bytesio.c:337\n#6  _io_BytesIO_getbuffer (self=\u003c_io.BytesIO at remote 0x7fffb4afccd0\u003e, cls=\u003coptimized out\u003e,\n    args=\u003coptimized out\u003e, nargs=\u003coptimized out\u003e, kwnames=\u003coptimized out\u003e)\n    at ./Modules/_io/clinic/bytesio.c.h:103\n#7  0x0000555555a4316b in _PyObject_VectorcallTstate (tstate=0x5290011b2210,\n    callable=\u003cmethod_descriptor at remote 0x7fffb45560c0\u003e, args=0x7fffba170400, nargsf=0,\n    kwnames=\u003cunknown at remote 0xffff684f6ed\u003e) at ./Include/internal/pycore_call.h:169\n#8  0x0000555555dfb5aa in _PyEval_EvalFrameDefault (tstate=\u003coptimized out\u003e, frame=\u003coptimized out\u003e,\n    throwflag=\u003coptimized out\u003e) at Python/generated_cases.c.h:3850\n#9  0x0000555555ddcb03 in _PyEval_EvalFrame (tstate=0x5290011b2210, frame=0x529001176328, throwflag=0)\n    at ./Include/internal/pycore_ceval.h:119\n#10 _PyEval_Vector (tstate=0x5290011b2210, func=0x7fffb4a9a110, locals=0x0, args=\u003coptimized out\u003e,\n    argcount=1, kwnames=0x0) at Python/ceval.c:1913\n#11 0x0000555555a4f30b in _PyObject_VectorcallTstate (tstate=0x5290011b2210,\n    callable=\u003cfunction at remote 0x7fffb4a9a110\u003e, args=0x7fffba170400, nargsf=0, nargsf@entry=1,\n    kwnames=\u003cunknown at remote 0xffff684f6ed\u003e, kwnames@entry=0x0) at ./Include/internal/pycore_call.h:169\n#12 0x0000555555a4cb9f in method_vectorcall (method=\u003coptimized out\u003e, args=\u003coptimized out\u003e,\n    nargsf=\u003coptimized out\u003e, kwnames=\u003coptimized out\u003e) at Objects/classobject.c:72\n#13 0x0000555555e7f6cb in _PyObject_VectorcallTstate (tstate=0x5290011b2210,\n    callable=\u003cmethod at remote 0x7fffba0c00d0\u003e, args=0x7fff5f1ae6d8, nargsf=0, kwnames=0x0)\n    at ./Include/internal/pycore_call.h:169\n#14 context_run (self=\u003c_contextvars.Context at remote 0x7fffb4c89070\u003e, args=\u003coptimized out\u003e,\n    nargs=\u003coptimized out\u003e, kwnames=0x0) at Python/context.c:728\n#15 0x0000555555e09a25 in _PyEval_EvalFrameDefault (tstate=\u003coptimized out\u003e, frame=\u003coptimized out\u003e,\n    throwflag=\u003coptimized out\u003e) at Python/generated_cases.c.h:3521\n#16 0x0000555555ddcb03 in _PyEval_EvalFrame (tstate=0x5290011b2210, frame=0x529001176220, throwflag=0)\n    at ./Include/internal/pycore_ceval.h:119\n#17 _PyEval_Vector (tstate=0x5290011b2210, func=0x7fffb4a9a1f0, locals=0x0, args=\u003coptimized out\u003e,\n    argcount=1, kwnames=0x0) at Python/ceval.c:1913\n#18 0x0000555555a4f30b in _PyObject_VectorcallTstate (tstate=0x5290011b2210,\n    callable=\u003cfunction at remote 0x7fffb4a9a1f0\u003e, args=0x7fffba170400, nargsf=0, nargsf@entry=1,\n    kwnames=\u003cunknown at remote 0xffff684f6ed\u003e, kwnames@entry=0x0) at ./Include/internal/pycore_call.h:169\n#19 0x0000555555a4cb9f in method_vectorcall (method=\u003coptimized out\u003e, args=\u003coptimized out\u003e,\n    nargsf=\u003coptimized out\u003e, kwnames=\u003coptimized out\u003e) at Objects/classobject.c:72\n#20 0x000055555612d7ae in thread_run (boot_raw=boot_raw@entry=0x507000010b80)\n    at ./Modules/_threadmodule.c:353\n#21 0x0000555555fe705d in pythread_wrapper (arg=\u003coptimized out\u003e) at Python/thread_pthread.h:242\n#22 0x000055555585cd47 in asan_thread_start(void*) ()\n#23 0x00007ffff7cfeac3 in start_thread (arg=\u003coptimized out\u003e) at ./nptl/pthread_create.c:442\n#24 0x00007ffff7d90850 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81\n```\n\nSegfault backtrace 3 (this one only happened with code similar to the MRE, not from this exact code):\n```\nThread 562 \"Thread-561 (get\" received signal SIGSEGV, Segmentation fault.\n[Switching to Thread 0xfffebe06f100 (LWP 2600253)]\n_Py_REFCNT (ob=0x0) at ./Include/refcount.h:109\n109             uint32_t local = _Py_atomic_load_uint32_relaxed(\u0026ob-\u003eob_ref_local);\n\nReceived signal 11, stopping\n(gdb) bt\n#0  _Py_REFCNT (ob=0x0) at ./Include/refcount.h:109\n#1  bytesiobuf_getbuffer (op=\u003c_io._BytesIOBuffer at remote 0x200100a0060\u003e, view=0x200101200e0, flags=284) at ./Modules/_io/bytesio.c:1090\n#2  0x0000000000489e80 in PyObject_GetBuffer (obj=obj@entry=\u003c_io._BytesIOBuffer at remote 0x200100a0060\u003e, view=view@entry=0x200101200e0, flags=flags@entry=284)\n    at Objects/abstract.c:445\n#3  0x00000000005499bc in _PyManagedBuffer_FromObject (base=base@entry=\u003c_io._BytesIOBuffer at remote 0x200100a0060\u003e, flags=flags@entry=284)\n    at Objects/memoryobject.c:97\n#4  0x0000000000549abc in PyMemoryView_FromObjectAndFlags (v=v@entry=\u003c_io._BytesIOBuffer at remote 0x200100a0060\u003e, flags=flags@entry=284)\n    at Objects/memoryobject.c:813\n#5  0x000000000054bf1c in PyMemoryView_FromObject (v=v@entry=\u003c_io._BytesIOBuffer at remote 0x200100a0060\u003e) at Objects/memoryobject.c:856\n#6  0x00000000007f3794 in _io_BytesIO_getbuffer_impl (self=0x2000691c790, cls=\u003coptimized out\u003e) at ./Modules/_io/bytesio.c:337\n#7  0x00000000007f393c in _io_BytesIO_getbuffer (self=\u003coptimized out\u003e, cls=\u003coptimized out\u003e, args=\u003coptimized out\u003e, nargs=\u003coptimized out\u003e, kwnames=\u003coptimized out\u003e)\n    at ./Modules/_io/clinic/bytesio.c.h:103\n#8  0x000000000054deac in cfunction_vectorcall_FASTCALL_KEYWORDS_METHOD (func=\u003cbuiltin_method at remote 0x2000691e5c0\u003e, args=0xb2d058 \u003c_PyRuntime+130520\u003e, \n    nargsf=\u003coptimized out\u003e, kwnames=0x0) at Objects/methodobject.c:486\n#9  0x00000000004b994c in _PyVectorcall_Call (tstate=tstate@entry=0xc3d0d0, func=0x54dce0 \u003ccfunction_vectorcall_FASTCALL_KEYWORDS_METHOD\u003e, \n    callable=callable@entry=\u003cbuiltin_method at remote 0x2000691e5c0\u003e, tuple=tuple@entry=(), kwargs=kwargs@entry={}) at Objects/call.c:273\n#10 0x00000000004b9d30 in _PyObject_Call (tstate=0xc3d0d0, callable=callable@entry=\u003cbuiltin_method at remote 0x2000691e5c0\u003e, args=(), kwargs={}) at Objects/call.c:348\n#11 0x00000000004b9d8c in PyObject_Call (callable=callable@entry=\u003cbuiltin_method at remote 0x2000691e5c0\u003e, args=\u003coptimized out\u003e, kwargs=\u003coptimized out\u003e)\n    at Objects/call.c:373\n#12 0x00000000006a2f20 in _PyEval_EvalFrameDefault (tstate=tstate@entry=0xc3d0d0, frame=frame@entry=0xffffea6fb128, throwflag=throwflag@entry=0)\n    at Python/generated_cases.c.h:2449\n#13 0x00000000006d13ec in _PyEval_EvalFrame (throwflag=0, frame=0xffffea6fb128, tstate=0xc3d0d0) at ./Include/internal/pycore_ceval.h:119\n#14 _PyEval_Vector (tstate=0xc3d0d0, func=0x20002ada490, locals=locals@entry=0x0, args=0xfffebe06e268, argcount=1, kwnames=0x0) at Python/ceval.c:1913\n#15 0x00000000004b6e24 in _PyFunction_Vectorcall (func=\u003coptimized out\u003e, stack=\u003coptimized out\u003e, nargsf=\u003coptimized out\u003e, kwnames=\u003coptimized out\u003e) at Objects/call.c:413\n#16 0x00000000004bc7d8 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=1, args=0xfffebe06e268, callable=\u003cfunction at remote 0x20002ada490\u003e, tstate=0xc3d0d0)\n    at ./Include/internal/pycore_call.h:169\n#17 method_vectorcall (method=\u003coptimized out\u003e, args=\u003coptimized out\u003e, nargsf=\u003coptimized out\u003e, kwnames=0x0) at Objects/classobject.c:72\n#18 0x00000000006f5c70 in _PyObject_VectorcallTstate (tstate=tstate@entry=0xc3d0d0, callable=\u003cmethod at remote 0x200100300d0\u003e, args=args@entry=0xfffebe06e538, \n    nargsf=nargsf@entry=0, kwnames=kwnames@entry=0x0) at ./Include/internal/pycore_call.h:169\n#19 0x00000000006f739c in context_run (self=\u003c_contextvars.Context at remote 0x200054c61f0\u003e, args=0xfffebe06e530, nargs=1, kwnames=0x0) at Python/context.c:728\n#20 0x00000000006a7b30 in _PyEval_EvalFrameDefault (tstate=tstate@entry=0xc3d0d0, frame=0xffffea6fb098, frame@entry=0xffffea6fb020, throwflag=throwflag@entry=0)\n    at Python/generated_cases.c.h:3509\n#21 0x00000000006d13ec in _PyEval_EvalFrame (throwflag=0, frame=0xffffea6fb020, tstate=0xc3d0d0) at ./Include/internal/pycore_ceval.h:119\n#22 _PyEval_Vector (tstate=0xc3d0d0, func=0x20002ada570, locals=locals@entry=0x0, args=0xfffebe06e718, argcount=1, kwnames=0x0) at Python/ceval.c:1913\n#23 0x00000000004b6e24 in _PyFunction_Vectorcall (func=\u003coptimized out\u003e, stack=\u003coptimized out\u003e, nargsf=\u003coptimized out\u003e, kwnames=\u003coptimized out\u003e) at Objects/call.c:413\n#24 0x00000000004bc7d8 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=1, args=0xfffebe06e718, callable=\u003cfunction at remote 0x20002ada570\u003e, tstate=0xc3d0d0)\n    at ./Include/internal/pycore_call.h:169\n```\n\nSegfault backtrace 4:\n```\nThread 612 \"Thread-611 (cal\" received signal SIGSEGV, Segmentation fault.\n\n0x0000555556093f78 in _Py_atomic_load_uint32_relaxed (obj=0xc) at ./Include/cpython/pyatomic_gcc.h:367\n367     { return __atomic_load_n(obj, __ATOMIC_RELAXED); }\n\n#0  0x0000555556093f78 in _Py_atomic_load_uint32_relaxed (obj=0xc) at ./Include/cpython/pyatomic_gcc.h:367\n#1  _Py_REFCNT (ob=0x0) at ./Include/refcount.h:109\n#2  unshare_buffer (self=self@entry=0x7fffb4afc640, size=0) at ./Modules/_io/bytesio.c:115\n#3  0x0000555556094b0a in bytesiobuf_getbuffer (op=\u003c_io._BytesIOBuffer at remote 0x7fffce3601f0\u003e,\n    view=0x7fffce2c0400, flags=284) at ./Modules/_io/bytesio.c:1091\n#4  0x00005555559dfed1 in PyObject_GetBuffer (obj=obj@entry=\u003c_io._BytesIOBuffer at remote 0x7fffce3601f0\u003e,\n    view=0x0, view@entry=0x7fffce2c0400, flags=flags@entry=284) at Objects/abstract.c:445\n#5  0x0000555555b69e59 in _PyManagedBuffer_FromObject (\n    base=base@entry=\u003c_io._BytesIOBuffer at remote 0x7fffce3601f0\u003e, flags=flags@entry=284)\n    at Objects/memoryobject.c:97\n#6  0x0000555555b65759 in PyMemoryView_FromObjectAndFlags (\n    v=\u003c_io._BytesIOBuffer at remote 0x7fffce3601f0\u003e, flags=284) at Objects/memoryobject.c:813\n#7  0x0000555556091f8d in _io_BytesIO_getbuffer_impl (self=0x7fffb4afc640, cls=\u003coptimized out\u003e)\n    at ./Modules/_io/bytesio.c:337\n#8  _io_BytesIO_getbuffer (self=\u003c_io.BytesIO at remote 0x7fffb4afc640\u003e, cls=\u003coptimized out\u003e,\n    args=\u003coptimized out\u003e, nargs=\u003coptimized out\u003e, kwnames=\u003coptimized out\u003e)\n    at ./Modules/_io/clinic/bytesio.c.h:103\n#9  0x0000555555a4316b in _PyObject_VectorcallTstate (tstate=0x5290017ca210,\n    callable=\u003cmethod_descriptor at remote 0x7fffb45560c0\u003e, args=0x0, nargsf=284,\n    kwnames=\u003cunknown at remote 0xffff684f6ed\u003e) at ./Include/internal/pycore_call.h:169\n#10 0x0000555555dfb5aa in _PyEval_EvalFrameDefault (tstate=\u003coptimized out\u003e, frame=\u003coptimized out\u003e,\n    throwflag=\u003coptimized out\u003e) at Python/generated_cases.c.h:3850\n#11 0x0000555555ddcb03 in _PyEval_EvalFrame (tstate=0x5290017ca210, frame=0x529001810328, throwflag=0)\n    at ./Include/internal/pycore_ceval.h:119\n#12 _PyEval_Vector (tstate=0x5290017ca210, func=0x7fffb4a9a110, locals=0x0, args=\u003coptimized out\u003e,\n    argcount=1, kwnames=0x0) at Python/ceval.c:1913\n#13 0x0000555555a4f30b in _PyObject_VectorcallTstate (tstate=0x5290017ca210,\n    callable=\u003cfunction at remote 0x7fffb4a9a110\u003e, args=0x0, nargsf=284, nargsf@entry=1,\n    kwnames=\u003cunknown at remote 0xffff684f6ed\u003e, kwnames@entry=0x0) at ./Include/internal/pycore_call.h:169\n#14 0x0000555555a4cb9f in method_vectorcall (method=\u003coptimized out\u003e, args=\u003coptimized out\u003e,\n    nargsf=\u003coptimized out\u003e, kwnames=\u003coptimized out\u003e) at Objects/classobject.c:72\n#15 0x0000555555e7f6cb in _PyObject_VectorcallTstate (tstate=0x5290017ca210,\n    callable=\u003cmethod at remote 0x7fffce042410\u003e, args=0x7fff5ecb56d8, nargsf=0, kwnames=0x0)\n    at ./Include/internal/pycore_call.h:169\n#16 context_run (self=\u003c_contextvars.Context at remote 0x7fffb4c78dd0\u003e, args=\u003coptimized out\u003e,\n    nargs=\u003coptimized out\u003e, kwnames=0x0) at Python/context.c:728\n#17 0x0000555555e09a25 in _PyEval_EvalFrameDefault (tstate=\u003coptimized out\u003e, frame=\u003coptimized out\u003e,\n    throwflag=\u003coptimized out\u003e) at Python/generated_cases.c.h:3521\n#18 0x0000555555ddcb03 in _PyEval_EvalFrame (tstate=0x5290017ca210, frame=0x529001810220, throwflag=0)\n    at ./Include/internal/pycore_ceval.h:119\n#19 _PyEval_Vector (tstate=0x5290017ca210, func=0x7fffb4a9a1f0, locals=0x0, args=\u003coptimized out\u003e,\n    argcount=1, kwnames=0x0) at Python/ceval.c:1913\n#20 0x0000555555a4f30b in _PyObject_VectorcallTstate (tstate=0x5290017ca210,\n    callable=\u003cfunction at remote 0x7fffb4a9a1f0\u003e, args=0x0, nargsf=284, nargsf@entry=1,\n    kwnames=\u003cunknown at remote 0xffff684f6ed\u003e, kwnames@entry=0x0) at ./Include/internal/pycore_call.h:169\n#21 0x0000555555a4cb9f in method_vectorcall (method=\u003coptimized out\u003e, args=\u003coptimized out\u003e,\n    nargsf=\u003coptimized out\u003e, kwnames=\u003coptimized out\u003e) at Objects/classobject.c:72\n#22 0x000055555612d7ae in thread_run (boot_raw=boot_raw@entry=0x507000014f50)\n    at ./Modules/_threadmodule.c:353\n#23 0x0000555555fe705d in pythread_wrapper (arg=\u003coptimized out\u003e) at Python/thread_pthread.h:242\n#24 0x000055555585cd47 in asan_thread_start(void*) ()\n#25 0x00007ffff7cfeac3 in start_thread (arg=\u003coptimized out\u003e) at ./nptl/pthread_create.c:442\n#26 0x00007ffff7d90850 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81\n```\n\nAbort backtrace:\n```\npython: ./Modules/_io/bytesio.c:116: int unshare_buffer(bytesio *, size_t): Assertion `self-\u003eexports == 0' failed.\n[New Thread 0x7fff6e740640 (LWP 999886)]\n[New Thread 0x7fff70553640 (LWP 999887)]\n[Thread 0x7fff7347f640 (LWP 999882) exited]\n\nThread 1349 \"Thread-1348 (ca\" received signal SIGABRT, Aborted.\n[Switching to Thread 0x7fff72c7e640 (LWP 999883)]\n__pthread_kill_implementation (no_tid=0, signo=6, threadid=140735119091264) at ./nptl/pthread_kill.c:44\n44      ./nptl/pthread_kill.c: No such file or directory.\n(gdb) bt\n#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=140735119091264) at ./nptl/pthread_kill.c:44\n#1  __pthread_kill_internal (signo=6, threadid=140735119091264) at ./nptl/pthread_kill.c:78\n#2  __GI___pthread_kill (threadid=140735119091264, signo=signo@entry=6) at ./nptl/pthread_kill.c:89\n#3  0x00007ffff7cac476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26\n#4  0x00007ffff7c927f3 in __GI_abort () at ./stdlib/abort.c:79\n#5  0x00007ffff7c9271b in __assert_fail_base (\n    fmt=0x7ffff7e47130 \"%s%s%s:%u: %s%sAssertion `%s' failed.\\n%n\",\n    assertion=0x555556388a20 \u003cstr\u003e \"self-\u003eexports == 0\",\n    file=0x555556387300 \u003cstr\u003e \"./Modules/_io/bytesio.c\", line=116, function=\u003coptimized out\u003e)\n    at ./assert/assert.c:94\n#6  0x00007ffff7ca3e96 in __GI___assert_fail (assertion=0x555556388a20 \u003cstr\u003e \"self-\u003eexports == 0\",\n    file=0x555556387300 \u003cstr\u003e \"./Modules/_io/bytesio.c\", line=line@entry=116,\n    function=0x555556388ae0 \u003c__PRETTY_FUNCTION__.unshare_buffer\u003e \"int unshare_buffer(bytesio *, size_t)\")\n    at ./assert/assert.c:103\n#7  0x00005555560941df in unshare_buffer (self=self@entry=0x7fffb46ca340, size=\u003coptimized out\u003e)\n    at ./Modules/_io/bytesio.c:116\n#8  0x0000555556094b0a in bytesiobuf_getbuffer (op=\u003c_io._BytesIOBuffer at remote 0x7fffbc0f0240\u003e,\n    view=0x7fffbc1804a0, flags=284) at ./Modules/_io/bytesio.c:1091\n#9  0x00005555559dfed1 in PyObject_GetBuffer (obj=obj@entry=\u003c_io._BytesIOBuffer at remote 0x7fffbc0f0240\u003e,\n    view=0xf41cb, view@entry=0x7fffbc1804a0, flags=6, flags@entry=284) at Objects/abstract.c:445\n#10 0x0000555555b69e59 in _PyManagedBuffer_FromObject (\n    base=base@entry=\u003c_io._BytesIOBuffer at remote 0x7fffbc0f0240\u003e, flags=flags@entry=284)\n    at Objects/memoryobject.c:97\n#11 0x0000555555b65759 in PyMemoryView_FromObjectAndFlags (\n    v=\u003c_io._BytesIOBuffer at remote 0x7fffbc0f0240\u003e, flags=284) at Objects/memoryobject.c:813\n#12 0x0000555556091f8d in _io_BytesIO_getbuffer_impl (self=0x7fffb46ca340, cls=\u003coptimized out\u003e)\n    at ./Modules/_io/bytesio.c:337\n#13 _io_BytesIO_getbuffer (self=\u003c_io.BytesIO at remote 0x7fffb46ca340\u003e, cls=\u003coptimized out\u003e,\n    args=\u003coptimized out\u003e, nargs=\u003coptimized out\u003e, kwnames=\u003coptimized out\u003e)\n    at ./Modules/_io/clinic/bytesio.c.h:103\n#14 0x0000555555a4316b in _PyObject_VectorcallTstate (tstate=0x5290034c6210,\n    callable=\u003cmethod_descriptor at remote 0x7fffb45560c0\u003e, args=0xf41cb, nargsf=6,\n    kwnames=\u003cunknown at remote 0x7fff72c7bd30\u003e) at ./Include/internal/pycore_call.h:169\n#15 0x0000555555dfb5aa in _PyEval_EvalFrameDefault (tstate=\u003coptimized out\u003e, frame=\u003coptimized out\u003e,\n    throwflag=\u003coptimized out\u003e) at Python/generated_cases.c.h:3850\n#16 0x0000555555ddcb03 in _PyEval_EvalFrame (tstate=0x5290034c6210, frame=0x52900348f328, throwflag=0)\n    at ./Include/internal/pycore_ceval.h:119\n#17 _PyEval_Vector (tstate=0x5290034c6210, func=0x7fffb4a9a110, locals=0x0, args=\u003coptimized out\u003e,\n    argcount=1, kwnames=0x0) at Python/ceval.c:1913\n#18 0x0000555555a4f30b in _PyObject_VectorcallTstate (tstate=0x5290034c6210,\n    callable=\u003cfunction at remote 0x7fffb4a9a110\u003e, args=0xf41cb, nargsf=6, nargsf@entry=1,\n    kwnames=\u003cunknown at remote 0x7fff72c7bd30\u003e, kwnames@entry=0x0) at ./Include/internal/pycore_call.h:169\n#19 0x0000555555a4cb9f in method_vectorcall (method=\u003coptimized out\u003e, args=\u003coptimized out\u003e,\n    nargsf=\u003coptimized out\u003e, kwnames=\u003coptimized out\u003e) at Objects/classobject.c:72\n#20 0x0000555555e7f6cb in _PyObject_VectorcallTstate (tstate=0x5290034c6210,\n    callable=\u003cmethod at remote 0x7fffbc0600d0\u003e, args=0x7fff72c7d6d8, nargsf=0, kwnames=0x0)\n    at ./Include/internal/pycore_call.h:169\n#21 context_run (self=\u003c_contextvars.Context at remote 0x7fffb46773f0\u003e, args=\u003coptimized out\u003e,\n    nargs=\u003coptimized out\u003e, kwnames=0x0) at Python/context.c:728\n#22 0x0000555555e09a25 in _PyEval_EvalFrameDefault (tstate=\u003coptimized out\u003e, frame=\u003coptimized out\u003e,\n    throwflag=\u003coptimized out\u003e) at Python/generated_cases.c.h:3521\n#23 0x0000555555ddcb03 in _PyEval_EvalFrame (tstate=0x5290034c6210, frame=0x52900348f220, throwflag=0)\n    at ./Include/internal/pycore_ceval.h:119\n#24 _PyEval_Vector (tstate=0x5290034c6210, func=0x7fffb4a9a1f0, locals=0x0, args=\u003coptimized out\u003e,\n    argcount=1, kwnames=0x0) at Python/ceval.c:1913\n#25 0x0000555555a4f30b in _PyObject_VectorcallTstate (tstate=0x5290034c6210,\n    callable=\u003cfunction at remote 0x7fffb4a9a1f0\u003e, args=0xf41cb, nargsf=6, nargsf@entry=1,\n    kwnames=\u003cunknown at remote 0x7fff72c7bd30\u003e, kwnames@entry=0x0) at ./Include/internal/pycore_call.h:169\n#26 0x0000555555a4cb9f in method_vectorcall (method=\u003coptimized out\u003e, args=\u003coptimized out\u003e,\n    nargsf=\u003coptimized out\u003e, kwnames=\u003coptimized out\u003e) at Objects/classobject.c:72\n#27 0x000055555612d7ae in thread_run (boot_raw=boot_raw@entry=0x5070000291c0)\n    at ./Modules/_threadmodule.c:353\n#28 0x0000555555fe705d in pythread_wrapper (arg=\u003coptimized out\u003e) at Python/thread_pthread.h:242\n#29 0x000055555585cd47 in asan_thread_start(void*) ()\n#30 0x00007ffff7cfeac3 in start_thread (arg=\u003coptimized out\u003e) at ./nptl/pthread_create.c:442\n#31 0x00007ffff7d90850 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81\n```\n\nRare error message:\n```\nException ignored while finalizing file \u003c_io.BytesIO object at 0x7fffb46b7f60\u003e:\nBufferError: Existing exports of data: object cannot be re-sized\nException ignored in the internal traceback machinery:\nImportError: sys.meta_path is None, Python is likely shutting down\nSystemError: deallocated BytesIO object has exported buffers\n```\n\nFound using [fusil](https://github.com/devdanzin/fusil) by @vstinner.\n\n\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n### Output from running 'python -VV' on the command line:\n\nPython 3.14.0a7+ experimental free-threading build (heads/main:c7f6535e4a3, Apr 15 2025, 09:09:58) [GCC 11.4.0]\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-132616\n* gh-137073\n* gh-138551\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/devdanzin","@type":"Person","name":"devdanzin"},"datePublished":"2025-04-15T12:26:10.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":7},"url":"https://github.com/132551/cpython/issues/132551"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:241dbcf3-ca83-8e0f-c101-e305934e8996
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idBBB0:203A5F:1E5B2B6:296C1A4:6A540874
html-safe-nonce334d0babaa31ec94890246fd79b1ec66f7ecd134a7af1ef283c91561dccaef1f
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQkIwOjIwM0E1RjoxRTVCMkI2OjI5NkMxQTQ6NkE1NDA4NzQiLCJ2aXNpdG9yX2lkIjoiNzU1ODg1Mzg1OTU5NjMwNjU0OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac5eeaaa035630f7e7281eb9293d870ed891dba4ac3e487b92b4c1aeec86673c56
hovercard-subject-tagissue:2996255833
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/132551/issue_layout
twitter:imagehttps://opengraph.githubassets.com/e3c95ac85ed06adbae55c6a20d86e5e44eb82756cf212809a6578dac5692ca90/python/cpython/issues/132551
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/e3c95ac85ed06adbae55c6a20d86e5e44eb82756cf212809a6578dac5692ca90/python/cpython/issues/132551
og:image:altCrash report What happened? This seems to be almost the same issue as #111174, but for free-threaded builds. In a free-threaded build it's possible to segfault (rare on debug build) or abort (commo...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamedevdanzin
hostnamegithub.com
expected-hostnamegithub.com
Noneb9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release07a982c1d40157c619b364352b704c3ce66bb332
ui-targetcanary-2
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/132551#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F132551
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F132551
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/132551
Reloadhttps://github.com/python/cpython/issues/132551
Reloadhttps://github.com/python/cpython/issues/132551
Please reload this pagehttps://github.com/python/cpython/issues/132551
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/132551
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 35k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 73.8k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.3k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality 0 https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Segfault/abort from calling BytesIO unshare_buffer in threads on a free-threaded buildhttps://github.com/python/cpython/issues/132551#top
3.13bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.13%22
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
topic-free-threadinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-free-threading%22
type-crashA hard crash of the interpreter, possibly with a core dumphttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-crash%22
https://github.com/devdanzin
devdanzinhttps://github.com/devdanzin
on Apr 15, 2025https://github.com/python/cpython/issues/132551#issue-2996255833
#111174https://github.com/python/cpython/issues/111174
fusilhttps://github.com/devdanzin/fusil
@vstinnerhttps://github.com/vstinner
gh-132551: make BytesIO object free-thread safe #132616https://github.com/python/cpython/pull/132616
gh-132551: add missing critical sections on BytesIO methods #137073https://github.com/python/cpython/pull/137073
[3.14] gh-132551: make io.BytesIO thread safe (GH-132616) #138551https://github.com/python/cpython/pull/138551
3.13bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.13%22
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
topic-free-threadinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-free-threading%22
type-crashA hard crash of the interpreter, possibly with a core dumphttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-crash%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.