raj
11/05/2025, 11:58 AMMarvin
11/05/2025, 11:58 AMMarvin
11/05/2025, 12:04 PMprefect config set PREFECT_API_ENABLE_HTTP2=false
- Or via environment variable before starting your worker/flow:
export PREFECT_API_ENABLE_HTTP2=false
- You can confirm your setting with:
prefect config view
If you need to set it in code for a specific client
from prefect.client.orchestration import get_client
async def use_api():
async with get_client(httpx_settings={"http2": False}) as client:
# make API calls
...
Why this helps
- The error is specific to HTTP/2 connection state transitions (server sends a PING after the connection has been closed). Using HTTP/1.1 avoids that code path entirely.
Additional steps (optional)
- Update the HTTP stack in your environment (often resolves edge cases):
pip install -U httpx httpcore h2
- If you must keep HTTP/2 enabled, you can try reducing connection reuse (e.g., disabling keep-alive or lowering keep-alive limits) via httpx_settings, but disabling HTTP/2 is the simplest and most reliable fix.
A few questions to help us tailor a fix
- Which Prefect version are you on? (Assuming 3.x unless you say otherwise.)
- Prefect Cloud or Prefect Server/self-hosted?
- Where is this running (local, Docker, Kubernetes), and is there a proxy/ingress in front of the API?
- Does it happen after flows sit idle for a while or randomly during normal operation?
- Can you share a slightly larger slice of the stack trace to confirm it’s happening in the Prefect API client?
Docs for reference
- Prefect settings (including PREFECT_API_ENABLE_HTTP2): Settings reference
- Prefect client and `get_client(httpx_settings=...)`: Client (orchestration) API