https://prefect.io logo
Title
s

Stephen Lloyd

04/21/2023, 4:43 AM
Any ideas as to what might be causing this h2 error? My flow and many tasks run successfully. Then, the following task seems to produce the failure (both in thread). The task itself is mapped with a concurrency limit of 8. Thousands of api calls are being made. I have not found any other error messages in the logs so far, but I'm continuing to look.
1
def loading(creds: Dict, task_list: List) -> List:
    workstream_id = creds["workstream_id"]
    api_key = creds["workstream_api_key"]

    error_response_list = []

    api = etl.TaskCompletedApi(run_env, workstream_id, api_key)
    for task in task_list:
        try:
            response = api.request(task)
            if response.json()["message"] != "Data successfully received":
                error_response_list.append(task)
        except:
            error_response_list.append(task)
    return error_response_list
Crash detected! Execution was interrupted by an unexpected exception: Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/h2/connection.py", line 224, in process_input
    func, target_state = self._transitions[(self.state, input_)]
                         ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
KeyError: (<ConnectionState.CLOSED: 3>, <ConnectionInputs.SEND_HEADERS: 0>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/httpcore/_async/http2.py", line 116, in handle_async_request
    await self._send_request_headers(request=request, stream_id=stream_id)
  File "/usr/local/lib/python3.11/site-packages/httpcore/_async/http2.py", line 213, in _send_request_headers
    self._h2_state.send_headers(stream_id, headers, end_stream=end_stream)
  File "/usr/local/lib/python3.11/site-packages/h2/connection.py", line 766, in send_headers
    self.state_machine.process_input(ConnectionInputs.SEND_HEADERS)
  File "/usr/local/lib/python3.11/site-packages/h2/connection.py", line 228, in process_input
    raise ProtocolError(
h2.exceptions.ProtocolError: Invalid input ConnectionInputs.SEND_HEADERS in state ConnectionState.CLOSED

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
    yield
  File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/httpcore/_async/connection_pool.py", line 253, in handle_async_request
    raise exc
  File "/usr/local/lib/python3.11/site-packages/httpcore/_async/connection_pool.py", line 237, in handle_async_request
    response = await connection.handle_async_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/httpcore/_async/connection.py", line 90, in handle_async_request
    return await self._connection.handle_async_request(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/httpcore/_async/http2.py", line 152, in handle_async_request
    raise LocalProtocolError(exc)  # pragma: nocover
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
httpcore.LocalProtocolError: Invalid input ConnectionInputs.SEND_HEADERS in state ConnectionState.CLOSED

The above exception was the direct cause of the following exception:

httpx.LocalProtocolError: Invalid input ConnectionInputs.SEND_HEADERS in state ConnectionState.CLOSED
@Emil Christensen Do you know what might be causing this?
e

Emil Christensen

04/26/2023, 2:21 PM
Hey @Stephen Lloyd 👋 you can read all about it here. The TL;DR is basically to disable it by setting
PREFECT_API_ENABLE_HTTP2=false
. HTTP2 is more efficient, but there are some bugs in the upstream libraries that have to get fixed.
s

Stephen Lloyd

04/27/2023, 6:00 AM
cc: @Susan Joshi
Thanks, @Emil Christensen. I'll do a better job looking for issues next time.