Fatal Python error: Segmentation fault · Issue #13203 · aio-libs/aiohttp · GitHub
Skip to content

Fatal Python error: Segmentation fault #13203

Closed

Description

@syteweb740-max

Describe the bug

My code I use to run everyday started showing error after the recent update ,
It starts by showing me some warning: net time use this else it won't work in the next update and I fix as it says and update aiohttp with python, the I start encounters this bug

Fatal Python error: Segmentation fault

Current thread's C stack trace (most recent call first):

Extension modules: _cffi_backend, aiohttp._http_writer, aiohttp._http_parser, aiohttp._websocket.mask, aiohttp._websocket.reader_c (total: 5)
Segmentation faultt

To Reproduce

Just look at the infos above

Expected behavior

Decoding responds fails on some site and instead of it to raise Expectation it crush
Am already using try and except Exception

Most crush here
Body = await response.text(errors="ignore")

Logs/tracebacks

Fatal Python error: Segmentation fault
                                                                Thread 0x00000073033f8cb0 (most recent call first):
  File "/data/data/com.termux/files/usr/lib/python3.14/site-packages/pycares/__init__.py", line 430 in _run_safe_shutdown_loop
  File "/data/data/com.termux/files/usr/lib/python3.14/threading.py", line 1024 in run
  File "/data/data/com.termux/files/usr/lib/python3.14/threading.py", line 1082 in _bootstrap_inner
  File "/data/data/com.termux/files/usr/lib/python3.14/threading.py", line 1044 in _bootstrap
                                                                Current thread 0x0000007395ae4098 (most recent call first):
  File "/data/data/com.termux/files/usr/lib/python3.14/site-packages/aiohttp/client_proto.py", line 326 in data_received
  File "/data/data/com.termux/files/usr/lib/python3.14/site-packages/aiohttp/base_protocol.py", line 89 in resume_reading
  File "/data/data/com.termux/files/usr/lib/python3.14/site-packages/aiohttp/client_proto.py", line 194 in resume_reading
  File "/data/data/com.termux/files/usr/lib/python3.14/site-packages/aiohttp/streams.py", line 556 in _read_nowait_chunk
  File "/data/data/com.termux/files/usr/lib/python3.14/site-packages/aiohttp/streams.py", line 568 in _read_nowait
  File "/data/data/com.termux/files/usr/lib/python3.14/site-packages/aiohttp/streams.py", line 462 in readany
  File "/data/data/com.termux/files/usr/lib/python3.14/site-packages/aiohttp/streams.py", line 437 in read
  File "/data/data/com.termux/files/usr/lib/python3.14/site-packages/aiohttp/client_reqrep.py", line 715 in read
  File "/storage/emulated/0/test/test-eye/s/mycode.py", line 722 in worker4
  File "/storage/emulated/0/test/test-eye/s/mycode.py", line 614 in worker2
  File "/data/data/com.termux/files/usr/lib/python3.14/asyncio/events.py", line 94 in _run
  File "/data/data/com.termux/files/usr/lib/python3.14/asyncio/base_events.py", line 2056 in _run_once                            File "/data/data/com.termux/files/usr/lib/python3.14/asyncio/base_events.py", line 677 in run_forever
  File "/data/data/com.termux/files/usr/lib/python3.14/asyncio/base_events.py", line 706 in run_until_complete
  File "/data/data/com.termux/files/usr/lib/python3.14/asyncio/runners.py", line 128 in run
  File "/data/data/com.termux/files/usr/lib/python3.14/asyncio/runners.py", line 205 in run
  File "/storage/emulated/0/test/test-eye/s/mycode.py", line 1367 in <module>

Current thread's C stack trace (most recent call first):
  <cannot get C stack on this system>

Extension modules: _cffi_backend, aiohttp._http_writer, aiohttp._http_parser, aiohttp._websocket.mask, aiohttp._websocket.reader_c (total: 5)
Segmentation fault

Python Version

Python 3.14.6

aiohttp Version

$ python -m pip show aiohttp
Name: aiohttp
Version: 3.14.2

multidict Version

Name: multidict
Version: 6.7.1                                                  Summary: multidict implementation

propcache Version

Name: propcache
Version: 0.5.2

yarl Version

Name: yarl
Version: 1.24.5

OS

Termux

Related component

Server

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct

Activity

  1. Dreamsorcerer commented on Jul 21, 2026

    @Dreamsorcerer
    Member

    Can you test without aiodns installed? And if that works, then verify that you were using the latest version of both aiodns and pycares.

  2. syteweb740-max commented on Jul 21, 2026

    @syteweb740-max
    Author

    Can you test without aiodns installed? And if that works, then verify that you were using the latest version of both aiodns and pycares.

    I think it's from aiohttp, i remove aiodns and it usage from my code still crush

    I think the best solution is to switch to httpx

  3. Dreamsorcerer commented on Jul 21, 2026

    @Dreamsorcerer
    Member

    I think it's from aiohttp, i remove aiodns and it usage from my code still crush

    Your traceback shows pycares, which is used by aiodns. Please follow the instructions and confirm the results. We can't help you if you don't give us any information...

  4. Dreamsorcerer commented on Jul 21, 2026

    @Dreamsorcerer
    Member

    If it's still failing without aiodns, then please paste the full traceback again.

  5. Dreamsorcerer commented on Jul 21, 2026

    @Dreamsorcerer
    Member

    Also verifying if it works without extensions (run with AIOHTTP_NO_EXTENSIONS=1) would help. That will tell us if it's a parser issue (we upgraded llhttp), and that's the only C code we run.

    I'm unclear how your code works though, it appears to be using threading, which generally doesn't make sense in an asyncio application.. Any code to look at or reproduce the issue would obviously be very helpful.

  6. Dreamsorcerer commented on Jul 21, 2026

    @Dreamsorcerer
    Member

    File "/data/data/com.termux/files/usr/lib/python3.14/site-packages/aiohttp/client_proto.py", line 326 in data_received

    This line is feeding data to the parser, so it probably is related to the C parser (llhttp). But, we need more information on how to reproduce. Can you provide code that shows the problem?

  7. added
    needs-infoIssue is lacking sufficient information and will be closed if not provided
    on Jul 21, 2026
  8. syteweb740-max commented on Jul 22, 2026

    @syteweb740-max
    Author

    File "/data/data/com.termux/files/usr/lib/python3.14/site-packages/aiohttp/client_proto.py", line 326 in data_received

    This line is feeding data to the parser, so it probably is related to the C parser (llhttp). But, we need more information on how to reproduce. Can you provide code that shows the problem?

    Please I remove aiodns, uvloop completely from my code and still crash

    Fatal Python error: Segmentation fault
    Current thread 0x000000756c59f098 (most recent call first): File "/data/data/com.termux/files/usr/lib/python3.14/site-packages/aiohttp/client_proto.py", line 326 in data_received File "/data/data/com.termux/files/usr/lib/python3.14/site-packages/aiohttp/base_protocol.py", line 89 in resume_reading
    File "/data/data/com.termux/files/usr/lib/python3.14/site-packages/aiohttp/client_proto.py", line 194 in resume_reading
    File "/data/data/com.termux/files/usr/lib/python3.14/site-packages/aiohttp/streams.py", line 556 in _read_nowait_chunk File "/data/data/com.termux/files/usr/lib/python3.14/site-packages/aiohttp/streams.py", line 569 in _read_nowait
    File "/data/data/com.termux/files/usr/lib/python3.14/site-packages/aiohttp/streams.py", line 462 in readany File "/data/data/com.termux/files/usr/lib/python3.14/site-packages/aiohttp/streams.py", line 437 in read
    File "/data/data/com.termux/files/usr/lib/python3.14/site-packages/aiohttp/client_reqrep.py", line 715 in read
    File "/data/data/com.termux/files/usr/lib/python3.14/site-packages/aiohttp/client_reqrep.py", line 757 in text
    File "/storage/emulated/0/test/test-eye/s/news.py", line 730 in sprayworker
    File "/storage/emulated/0/test/test-eye/s/news.py", line 622 in worker2
    File "/data/data/com.termux/files/usr/lib/python3.14/asyncio/events.py", line 94 in _run
    File "/data/data/com.termux/files/usr/lib/python3.14/asyncio/base_events.py", line 2056 in _run_once
    File "/data/data/com.termux/files/usr/lib/python3.14/asyncio/base_events.py", line 677 in run_forever File "/data/data/com.termux/files/usr/lib/python3.14/asyncio/base_events.py", line 706 in run_until_complete
    File "/data/data/com.termux/files/usr/lib/python3.14/asyncio/runners.py", line 128 in run
    File "/data/data/com.termux/files/usr/lib/python3.14/asyncio/runners.py", line 205 in run
    File "/storage/emulated/0/test/test-eye/s/news.py", line 1374 in
    Current thread's C stack trace (most recent call first):

    Extension modules: _cffi_backend, aiohttp._http_writer, aiohttp._http_parser, aiohttp._websocket.mask, aiohttp._websocket.reader_c (total: 5)
    Segmentation fault

    The error in my code and what is found over there
    1.File "/storage/emulated/0/test/test-eye/s/news.py", line 730 in sprayworker
    line 730
    body = await r.text(errors='ignore')

    File "/storage/emulated/0/test/test-eye/s/news.py", line 622 in worker2

    line 622
    ex_tabl = await sprayworker(data, "table")

  9. removed
    needs-infoIssue is lacking sufficient information and will be closed if not provided
    on Jul 22, 2026
  10. syteweb740-max commented on Jul 22, 2026

    @syteweb740-max
    Author

    It's a scraper tools, scraping from many urls and it crash after few seconds after starting (sometimes it runs about 4-6sec then crash sometimes 30-40sec) it should raise expectation but it crashes, before update I use to run the same site successfully without any crash even at high Semaphore

    my complete imports
    Key: all # lines are commented real in my code

    import faulthandler
    faulthandler.enable()
    import os
    import re
    import ssl
    import ast
    import json
    import time
    #import uvloop
    import random
    #import certifi
    import asyncio
    import aiohttp
    import hashlib
    from colorama import Fore, Style, init
    from fake_useragent import UserAgent
    #from aiohttp.resolver import AsyncResolver
    from urllib.parse import urlparse, parse_qs, urlencode, urlunparse
    #the below is advice use by AI to stop the crash
    os.environ['AIOHTTP_NO_EXTENSIONS'] = '1'
    os.environ['UVLOOP_NO_EXTENSIONS'] = '1'

    And still crash

  11. Dreamsorcerer commented on Jul 22, 2026

    @Dreamsorcerer
    Member

    Again, test with AIOHTTP_NO_EXTENSIONS (set this as the environment variable for the program, not inside the code).

    And give us some code or anything (e.g. the payload that causes the failure; log each request you make so you know which request actually triggers the failure) that we can use to figure out what the problem is.

  12. syteweb740-max commented on Jul 22, 2026

    @syteweb740-max
    Author

    Yes AIOHTTP_NO_EXTENSIONS=1 python your_script.py works without crashing

  13. 11 remaining items

  14. taulantarapi commented on Jul 22, 2026

    @taulantarapi

    it still segfaults on 3.14.3

  15. syteweb740-max commented on Jul 22, 2026

    @syteweb740-max
    Author

    ERROR: No matching distribution found for aiohttp==3.14.3

    Or aiohttp version 3.14.3 has not been release yet

  16. taulantarapi commented on Jul 23, 2026

    @taulantarapi

    i couldn't find it either in pypi, but there are whl files here on github or you can install it from source

  17. syteweb740-max commented on Jul 23, 2026

    @syteweb740-max
    Author

    From github here they haven't update it yet, may be it will be update later

  18. Dreamsorcerer commented on Jul 23, 2026

    @Dreamsorcerer
    Member

    Thanks @taulantarapi for the email report, that's been really helpful.

    We're still investigating the precise details, but right now it looks like a bug in brotlicffi, so I'd suggest you both uninstall that library for the moment.

  19. Dreamsorcerer commented on Jul 23, 2026

    @Dreamsorcerer
    Member
  20. syteweb740-max commented on Jul 23, 2026

    @syteweb740-max
    Author

    Brotlicffi might be the cause of the crash because requests fail to decode the response too but raised Exception not crash so my suggestion is, add that error to aiohttp to raise Exception when such decoding fails

  21. syteweb740-max commented on Jul 23, 2026

    @syteweb740-max
    Author

    Because I just checked brotlicffi repo from GitHub here and it hasn't been update recently so it's possible from aiohttp, aiohttp old version was not crashing, my suggestion is if brotlicffi fails raise Exception not crash, please take a look at it

  22. Dreamsorcerer commented on Jul 23, 2026

    @Dreamsorcerer
    Member

    The issue appeared in 1.2. When 1.2 was released we made a security fix which was a bit of a hack, but happened to also avoid the newly broken code path in brotlicffi. aiohttp 3.14 contained our complete fix that re-enabled that code path.

    So problem exists with aiohttp 3.14+ and brotlicffi 1.2. We also require 1.2+ for our security fix, so the only option currently is to uninstall brotlicffi. I'll check if the segfault can be resolved, but you still want to uninstall it, because those exceptions are still stopping you from reading legitimate responses.

  23. Dreamsorcerer commented on Jul 23, 2026

    @Dreamsorcerer
    Member

    Note that this problem doesn't exist in brotli. I assume you're on a less common platform, where Google's brotli is not supported.

  24. syteweb740-max commented on Jul 23, 2026

    @syteweb740-max
    Author

    Yes after uninstalling brotlicffi it works👍 without crashing

  25. Dreamsorcerer commented on Jul 26, 2026

    @Dreamsorcerer
    Member
  26. Dreamsorcerer commented on Aug 22, 2026

    @Dreamsorcerer
    Member

    v1.2.0.2 is out now, you can reinstall brotlicffi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions