MagicStack / MagicStack/uvloop

Python 3.13 Error Walking Stack w/ PYTHONASYNCIODEBUG=1

Open
#730 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Cython
Stars
11.9k
Forks
616
PR merge metrics
No merged PRs in 30d

Description

There appears to be a bug in uvloop for python 3.13 walking the stack when PYTHONASYNCIODEBUG=1 and there are c frames in the stack.

I suspect this is tied to changes in 3.13 with how [python handles frames ](https://docs.python.org/3/whatsnew/3.13.html#whatsnew313-locals-semantics)

To Repro:
Python 3.13
uvloop 0.22.1 (also confirmed it happens

run: `docker build -f Dockerfile.latest -t crash-test-latest . 2>&1 | tail -3 && echo "---" && docker run --rm crash-test-latest 2>&1; echo "exit: $?"`
exits w/ 139

If you go into the dockerfile and set `ENV PYTHONASYNCIODEBUG=` (instead of 1), exits w/ 0

Dockerfile:
```
FROM python:3.13-slim
RUN pip install uvloop==0.22.1
ENV PYTHONASYNCIODEBUG=1
COPY repro.py /repro.py
CMD ["python3", "/repro.py"]
```

Repro.py
```
import asyncio
import sys
import os

print(f"Python: {sys.version}")
print(f"Platform: {sys.platform}")
print(f"PYTHONASYNCIODEBUG: {os.environ.get('PYTHONASYNCIODEBUG', '')}")

import uvloop
print(f"uvloop: {uvloop.__version__}")

async def gen():
yield 1
yield 2

async def main():
x = gen()
await x.__anext__()
# x goes out of scope on function exit

uvloop.install()
asyncio.run(main())
print("NO CRASH")
```

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided Docker reproduction from Dockerfile.latest with repro.py under Python 3.13 and PYTHONASYNCIODEBUG=1, then compare it with the environment where the variable is unset. Trace the stack-walking failure involving the async generator and C frames; done means the reproduction exits successfully with debug mode enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.