Accept `ReadError` from a read pending during ASGI WebSocket close
Merged
KL
2d ago+4+4+0123456789-4-4-0123456789
Summary
test_read_during_and_after_close fails on anyio 4.16.0, as reported in https://github.com/pydantic/httpx2/discussions/1309.
Since anyio 4.16.0, closing a memory stream wakes a pending receive() with ClosedResourceError instead of EndOfStream. A read that is pending when aclose() runs now raises httpcore2.ReadError instead of returning b"".
Both outcomes are valid, so only the test changes:
AsyncWebSocketSessionhandlesReadErrorand EOF in the sameexceptclause.- The httpcore2 anyio backend also raises
ReadErrorwhen a read is interrupted by a local close.
The test now accepts either outcome for the pending read. It still requires ReadError for a read started after close.
Checklist
- I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
- I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
- I've updated the documentation accordingly.
Session: pi --session 01a1e9c9-f8a7-747b-8fb8-baaed8bd78de