Skip to content

Streamed request bodies and cookie jars can still crash the process at exit #612

Open

Description

@barjin

Streamed request bodies (request.rs) and custom cookie jars (cookies.rs) run user Python code on tokio threads outside the exit gate from #607, so if that code releases the GIL while the interpreter starts finalizing, the process aborts on Python < 3.13.8. This crashes on every run on 3.11:

import asyncio, socket, sys, time, types
import impit

class SlowTeardown:  # stands in for a big app's interpreter teardown
    def __del__(self, _now=time.perf_counter):
        end = _now() + 0.6
        while _now() < end:
            pass

m = types.ModuleType('_slow'); m.obj = SlowTeardown(); sys.modules['_slow'] = m; del m
server = socket.create_server(('127.0.0.1', 0))  # accepts the upload, never responds

def body():
    while True:
        time.sleep(0.3)  # user code on a tokio thread, GIL released
        yield b'x'

async def main():
    async with impit.AsyncClient() as client:
        try:
            await asyncio.wait_for(client.post(f'http://127.0.0.1:{server.getsockname()[1]}/', content=body()), 0.1)
        except TimeoutError:
            pass

asyncio.run(main())

Activity

  1. added
    t-toolingIssues with this label are in the ownership of the tooling team.
    on Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

t-toolingIssues with this label are in the ownership of the tooling team.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions