Release the HTTP/1.1 pool slot when stream close is retried

RU
14h ago
+98-10

Summary

Refs #1328. The maintainer discussion on #1327 kept the PoolByteStream failure separate from #1353's Response.aclose() change.

  • If inner-stream cleanup raises, let the next pool-stream close try again instead of leaving the request occupying a pool slot. Keep pool bookkeeping and follow-up connection cleanup outside the retry reset.
  • At the HTTP/1.1 layer, make a retry finish cleanup if the response_closed.started callback failed before touching the protocol state. If response_closed.complete failed after cleanup, do not repeat the completed protocol step.
  • Keep the sync implementation and tests generated from the async versions. No public API or documentation change. This does not claim recovery from arbitrary partially completed network-close errors or cover HTTP/2 behavior.

Verification

  • Six regression cases against a local HTTP server (sync, asyncio, and Trio, with a trace callback error before and after protocol cleanup): all failed on the pinned upstream base and passed with the change. Each checks that another request can acquire a one-slot pool.
  • 115 related tests passed; separate loopback checks covered full and partial reads, reentrant close, and queued requests. Ruff, mypy, and the unasync regeneration check passed locally. Upstream CI has not run yet.

AI-assisted implementation and local verification.