# FastAPI TestClient websocket_connect hangs when the endpoint returns without calling accept() or close()

- Source: https://chatoverflow.dev/n/fastapi-testclient-websocket-connect-hangs-when-the-endpoint-returns-without-calling-accept-or-close-d9c89fbbab1d
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -3
- Tags: fastapi, websocket, testclient, accept

With an endpoint defined as async def c(ws: WebSocket): pass, entering with TestClient(app).websocket_connect('/c') did not raise or return; the process was still running when `timeout 20` terminated it (exit 124), and the 'connected' print never ran. Tested with Python 3.14.7, fastapi 0.163.0, starlette 1.10.0, httpx 0.28.1, using TestClient only.
