Skip to content

Commit 6dab402

Browse files
committed
Fix lint failures (mypy, unasync) on the h2 send-lock change
- tests/_sync/test_http2_thread_safety.py: add type annotations so mypy strict passes (FakeStream now subclasses httpcore.NetworkStream, all methods annotated). - Align the new comments between httpcore/_async/http2.py (unasync source of truth) and httpcore/_sync/http2.py so scripts/unasync.py --check passes; use a magic trailing comma on the split _send_request_headers call so ruff format and unasync agree.
1 parent 32b8974 commit 6dab402

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

‎httpcore/_sync/http2.py‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ def handle_request(self, request: Request) -> Response:
141141

142142
try:
143143
# The send path mutates the shared `h2` state machine, which is
144-
# not thread-safe, so stream ID allocation and the send itself
145-
# are serialized under a single lock. Note that h2 requires
146-
# `get_next_available_stream_id()` to be immediately followed by
147-
# the matching `send_headers()` call, otherwise concurrent
148-
# threads may be handed duplicate stream IDs. Without this,
149-
# multithreaded clients sharing one connection hit errors such as
144+
# not safe for concurrent use, so stream ID allocation and the
145+
# send itself are serialized under a single lock. Note that h2
146+
# requires `get_next_available_stream_id()` to be immediately
147+
# followed by the matching `send_headers()` call, otherwise
148+
# concurrent callers may be handed duplicate stream IDs. Without
149+
# this, clients sharing one connection hit errors such as
150150
# "deque mutated during iteration", "dictionary changed size
151151
# during iteration", and `StreamIDTooLowError`.
152152
# (encode/httpx#3566)
@@ -155,7 +155,10 @@ def handle_request(self, request: Request) -> Response:
155155
self._events[stream_id] = []
156156
kwargs = {"request": request, "stream_id": stream_id}
157157
with Trace("send_request_headers", logger, request, kwargs):
158-
self._send_request_headers(request=request, stream_id=stream_id)
158+
self._send_request_headers(
159+
request=request,
160+
stream_id=stream_id,
161+
)
159162
with Trace("send_request_body", logger, request, kwargs):
160163
self._send_request_body(request=request, stream_id=stream_id)
161164
with Trace(

0 commit comments

Comments
 (0)