fix: HTTP 2.0 Throws KeyError rather than the internal exception thrown in th... - #1093
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
1 issue found across 4 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="tests/httpcore2/_sync/test_http2.py">
<violation number="1" location="tests/httpcore2/_sync/test_http2.py:99">
P2: The test calls `conn._response_closed` only once on a live stream. The docstring says the test is for the "twice" / already-removed scenario, but the second call that would exercise the fix's `if stream_id in self._events:` guard is missing. Add a second `conn._response_closed(stream_id=1)` call so the test actually verifies the no-op behavior on an already-removed stream.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| conn._response_closed(stream_id=1) | ||
|
|
||
|
|
There was a problem hiding this comment.
P2: The test calls conn._response_closed only once on a live stream. The docstring says the test is for the "twice" / already-removed scenario, but the second call that would exercise the fix's if stream_id in self._events: guard is missing. Add a second conn._response_closed(stream_id=1) call so the test actually verifies the no-op behavior on an already-removed stream.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tests/httpcore2/_sync/test_http2.py, line 99:
<comment>The test calls `conn._response_closed` only once on a live stream. The docstring says the test is for the "twice" / already-removed scenario, but the second call that would exercise the fix's `if stream_id in self._events:` guard is missing. Add a second `conn._response_closed(stream_id=1)` call so the test actually verifies the no-op behavior on an already-removed stream.</comment>
<file context>
@@ -69,6 +69,37 @@ def test_http2_connection_closed() -> None:
+ conn.request("GET", "https://example.com/")
+
+ # The stream was closed when the response completed.
+ conn._response_closed(stream_id=1)
+
+
</file context>
| conn._response_closed(stream_id=1) | |
| # Call twice: first close succeeds, second close must be a no-op (no KeyError). | |
| conn._response_closed(stream_id=1) | |
| conn._response_closed(stream_id=1) |
There was a problem hiding this comment.
This is not really a problem and should be ignored
Kludex
left a comment
There was a problem hiding this comment.
The cleanup is now idempotent under the state lock, and the semaphore permit is released only when the stream entry is actually removed. The regression test does exercise the duplicate-close path: conn.request() reads and closes the response, then the explicit _response_closed() call performs the second cleanup. Targeted HTTP/2 tests also pass against the current main branch.
Fixes #808.
Summary
HTTP 2.0 Throws KeyError rather than the internal exception thrown in the thread
Validation
🤖 AI-authored PR, operated by @yhay81.