aiohttp icon indicating copy to clipboard operation
aiohttp copied to clipboard

[Python 3.14t] `GunicornWebWorker` crashes on init when trying to close non-existent asyncio loop

Open Uncomfy opened this issue 2 months ago • 4 comments

Describe the bug

Gunicorn worker crashes on init when it tries to close event loop. Happens only in python 3.14, works correctly in 3.13

To Reproduce

  1. Implement a simple server:
from aiohttp import web

async def index(request):
    return web.Response(text="Welcome home!")

async def my_web_app():
    app = web.Application()
    app.router.add_get('/', index)
    return app
  1. Run it with gunicorn:
gunicorn my_app_module:my_web_app --bind localhost:8080 --worker-class aiohttp.GunicornWebWorker

Expected behavior

Server starts up

Logs/tracebacks

Traceback (most recent call last):
  File ".../env314t/lib/python3.14t/site-packages/gunicorn/arbiter.py", line 608, in spawn_worker
    worker.init_process()
    ~~~~~~~~~~~~~~~~~~~^^
  File ".../env314t/lib/python3.14t/site-packages/aiohttp/worker.py", line 52, in init_process
    asyncio.get_event_loop().close()
    ~~~~~~~~~~~~~~~~~~~~~~^^
  File ".../.local/share/uv/python/cpython-3.14.0+freethreaded-linux-x86_64-gnu/lib/python3.14t/asyncio/events.py", line 715, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'
                       % threading.current_thread().name)
RuntimeError: There is no current event loop in thread 'MainThread'.

Python Version

Python 3.14.0t

aiohttp Version

aiohttp 3.13.1

multidict Version

multidict 6.7.0

propcache Version

propcache 0.4.1

yarl Version

yarl 1.22.0

OS

Ubuntu 22.04

Related component

Server

Additional context

gunicorn 23.0.0

Code of Conduct

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

Uncomfy avatar Oct 21 '25 13:10 Uncomfy

Is this only happening under free-threading?

webknjaz avatar Oct 21 '25 13:10 webknjaz

On master, that code was actually removed: https://github.com/aio-libs/aiohttp/pull/3580/files#diff-fa9062813a095af1b8f81504f078fedfc4440c1ffbcb29e4fc8ce6e713cf8cd9

If you'd like to backport some of those changes to the 3.14 branch and it doesn't appear to break anything else, then we can merge that in for the next release.

Dreamsorcerer avatar Oct 21 '25 13:10 Dreamsorcerer

Is this only happening under free-threading?

No, it also happens in regular python 3.14.

If you'd like to backport some of those changes to the 3.14 branch and it doesn't appear to break anything else, then we can merge that in for the next release.

I'll take a look, but it will take some time, thank you for pointing me there. I'm a bit confused - that PR is 6 years old, why is it a part of master, but not a part of 3.14?

Uncomfy avatar Oct 21 '25 14:10 Uncomfy

master will be v4

Dreamsorcerer avatar Oct 21 '25 14:10 Dreamsorcerer