Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP 2.0 Throws KeyError rather than the internal exception thrown in the thread #3072

Open
1 task
Tracked by #3324
rocky4546 opened this issue Jan 25, 2024 · 0 comments
Open
1 task
Tracked by #3324
Labels
http/2 Issues and PRs related to HTTP/2

Comments

@rocky4546
Copy link

The starting point for issues should usually be a discussion...

https://github.com/encode/httpx/discussions

Possible bugs may be raised as a "Potential Issue" discussion, feature requests may be raised as an "Ideas" discussion. We can then determine if the discussion needs to be escalated into an "Issue" or not.

This will help us ensure that the "Issues" list properly reflects ongoing or needed work on the project.


  • Initially raised as discussion #...

We are running into a number of HTTP 2.0 protocol errors with a remote supplier. We have seen two exceptions that are raised internally, but when it makes it to the calling routine, it turns into a KeyError exception. Here are the exceptions:

EXCEPTION #1

Exception in thread Thread-809:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/http2.py", line 148, in handle_request
status, headers = self._receive_response(
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/http2.py", line 292, in _receive_response
event = self._receive_stream_event(request, stream_id)
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/http2.py", line 333, in _receive_stream_event
self._receive_events(request, stream_id)
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/http2.py", line 361, in _receive_events
events = self._read_incoming_data(request)
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/http2.py", line 454, in _read_incoming_data
events: typing.List[h2.events.Event] = self._h2_state.receive_data(data)
File "/usr/local/lib/python3.8/site-packages/h2/connection.py", line 1463, in receive_data
events.extend(self._receive_frame(frame))
File "/usr/local/lib/python3.8/site-packages/h2/connection.py", line 1487, in _receive_frame
frames, events = self._frame_dispatch_tableframe.class
File "/usr/local/lib/python3.8/site-packages/h2/connection.py", line 1561, in receive_headers_frame
frames, stream_events = stream.receive_headers(
File "/usr/local/lib/python3.8/site-packages/h2/stream.py", line 1041, in receive_headers
events = self.state_machine.process_input(input
)
File "/usr/local/lib/python3.8/site-packages/h2/stream.py", line 129, in process_input
return func(self, previous_state)
File "/usr/local/lib/python3.8/site-packages/h2/stream.py", line 338, in recv_on_closed_stream
raise StreamClosedError(self.stream_id)
h2.exceptions.StreamClosedError: 979

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
calling routine goes here...
File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1055, in get
return self.request(
File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 828, in request
return self.send(request, auth=auth, follow_redirects=follow_redirects)
File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 915, in send
response = self._send_handling_auth(
File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 943, in _send_handling_auth
response = self._send_handling_redirects(
File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 980, in _send_handling_redirects
response = self._send_single_request(request)
File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1016, in _send_single_request
response = transport.handle_request(request)
File "/usr/local/lib/python3.8/site-packages/httpx/_transports/default.py", line 231, in handle_request
resp = self._pool.handle_request(req)
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/connection_pool.py", line 268, in handle_request
raise exc
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/connection_pool.py", line 251, in handle_request
response = connection.handle_request(request)
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/connection.py", line 103, in handle_request
return self._connection.handle_request(request)
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/http2.py", line 167, in handle_request
self._response_closed(stream_id=stream_id)
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/http2.py", line 406, in _response_closed
del self._events[stream_id]
KeyError: 979

EXCEPTION #2

Exception in thread Thread-94:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/http2.py", line 148, in handle_request
status, headers = self._receive_response(
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/http2.py", line 292, in _receive_response
event = self._receive_stream_event(request, stream_id)
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/http2.py", line 333, in _receive_stream_event
self._receive_events(request, stream_id)
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/http2.py", line 352, in _receive_events
raise RemoteProtocolError(self._connection_terminated)
httpcore.RemoteProtocolError: <ConnectionTerminated error_code:ErrorCodes.PROTOCOL_ERROR, last_stream_id:7, additional_data:None>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
Exception in thread Thread-97:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/http2.py", line 148, in handle_request
status, headers = self._receive_response(
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/http2.py", line 292, in _receive_response
self.run()
File "/app/lib/streams/m3u8_queue.py", line 81, in run
event = self._receive_stream_event(request, stream_id)
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/http2.py", line 333, in _receive_stream_event
self._receive_events(request, stream_id)
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/http2.py", line 352, in _receive_events
raise RemoteProtocolError(self._connection_terminated)
httpcore.RemoteProtocolError: <ConnectionTerminated error_code:ErrorCodes.PROTOCOL_ERROR, last_stream_id:7, additional_data:None>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
calling routine goes here...
File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1055, in get
return self.request(
File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 828, in request
resp = self._pool.handle_request(req)
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/connection_pool.py", line 268, in handle_request
return self.send(request, auth=auth, follow_redirects=follow_redirects)
File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 915, in send
response = self._send_handling_auth(
File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 943, in _send_handling_auth
response = self._send_handling_redirects(
File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 980, in _send_handling_redirects
response = self._send_single_request(request)
File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1016, in _send_single_request
raise exc
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/connection_pool.py", line 251, in handle_request
response = connection.handle_request(request)
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/connection.py", line 103, in handle_request
return self._connection.handle_request(request)
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/http2.py", line 167, in handle_request
response = transport.handle_request(request)
File "/usr/local/lib/python3.8/site-packages/httpx/_transports/default.py", line 231, in handle_request
resp = self._pool.handle_request(req)
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/connection_pool.py", line 268, in handle_request
self._response_closed(stream_id=stream_id)
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/http2.py", line 406, in _response_closed
del self._events[stream_id]
KeyError: 5
raise exc
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/connection_pool.py", line 251, in handle_request
response = connection.handle_request(request)
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/connection.py", line 103, in handle_request
return self._connection.handle_request(request)
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/http2.py", line 167, in handle_request
self._response_closed(stream_id=stream_id)
File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/http2.py", line 406, in _response_closed
del self._events[stream_id]
KeyError: 3

@tomchristie tomchristie added the http/2 Issues and PRs related to HTTP/2 label Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http/2 Issues and PRs related to HTTP/2
Projects
None yet
Development

No branches or pull requests

2 participants