Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Description
Crash report
What happened?
importurllib3importgzipimportioimportjsonimportfaulthandlerfaulthandler.enable()deftest():buffer=gzip.GzipFile(fileobj=io.BytesIO(),mode="w",compresslevel=5)fileobj=buffer.fileobj# get a reference to the fileobj before closing the gzip filebuffer.close()data=fileobj.getbuffer()headers= {}try:urllib3.request("POST","http://127.0.0.1:8200/intake/v2/events")exceptExceptionase:print(e)test()
The above example requiresurllib3, so you'll need to install that first.
When the above example is run on Python 3.12.0, it results in a segfault:
HTTPConnectionPool(host='127.0.0.1', port=8200): Max retries exceeded with url: /intake/v2/events (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x1053c5280>: Failed to establish a new connection: [Errno 61] Connection refused'))Fatal Python error: Segmentation faultCurrent thread 0x00000001e1499300 (most recent call first): Garbage-collecting <no Python frame>[1] 38085 segmentation fault python test.pySome weird things:
- If I remove the
urllib3.request, it doesn't segfault. - If the
urllib3.requestsucceeds (in this case, if I run the Elastic APM Server locally), it doesn't segfault. - If I pull the code out of the function and run it flat, itdoesn't segfault 🤯:
importurllib3importgzipimportioimportjsonimportfaulthandlerfaulthandler.enable()buffer=gzip.GzipFile(fileobj=io.BytesIO(),mode="w",compresslevel=5)fileobj=buffer.fileobj# get a reference to the fileobj before closing the gzip filebuffer.close()data=fileobj.getbuffer()headers= {}try:urllib3.request("POST","http://127.0.0.1:8200/intake/v2/events")exceptExceptionase:print(e)
This is an extremely simplified version of the code where I first saw the segfault. Note that you don't even have to send thedata into theurllib3.request to cause the issue. You don't even have to write anything to the buffer! Note, writing to the buffer does not prevent the segfault.
I can reproduce this issue on cpython 3.12.0 (built viapyenv) locally on macOS and on thepython:3.12.0 docker image.
The segfault does not happen on 3.11 and below.
CPython versions tested on:
3.12, 3.11 (only happens on 3.12)
Operating systems tested on:
Linux, macOS
Output from running 'python -VV' on the command line:
Python 3.12.0 (main, Oct 2 2023, 17:34:07) [Clang 15.0.0 (clang-1500.0.40.1)]