Close the underlying stream when an AnyIO TLS handshake is cancelled
NI
7d ago+104+104+012345678901234567890123456789-3-3-0123456789
Summary
Catch BaseException and shield stream cleanup so outer cancellation cannot leave the underlying socket open. Preserve cancellation propagation and existing exception mapping.
Add deterministic coverage for asyncio and Trio cancellation, native asyncio deadlines, and ordinary TLS failures.
This surfaced to me in Weblate's test suite and was traced to httpcore2. Codex helped me with this.
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.