:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(temporalio): ride out transient h2 transport errors in-process (#71791)
Tom Owers17af3324dffe
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/temporalio/temporalio.py b/products/warehouse_sources/backend/temporal/data_imports/sources/temporalio/temporalio.pyindex 7333a4bfae09..9c84bfd5b094 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/temporalio/temporalio.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/temporalio/temporalio.py@@ -65,6 +65,19 @@ _MAX_TRANSIENT_RPC_ATTEMPTS = 6_RETRYABLE_RPC_STATUSES = frozenset({RPCStatusCode.RESOURCE_EXHAUSTED, RPCStatusCode.DEADLINE_EXCEEDED})+# tonic/hyper surface a mid-stream HTTP/2 transport interruption (a reset stream or a response+# body read cut short) as an RPCError with status UNKNOWN and an "h2 protocol error" message,+# rather than one of the transient statuses above. It's a connection blip, not the server+# rejecting the request, so ride it out the same way. Match the stable transport phrase, not the+# whole UNKNOWN status, so genuine server-side UNKNOWN failures still surface.+_RETRYABLE_RPC_MESSAGES = ("h2 protocol error",)+++def _is_retryable_rpc_error(error: RPCError) -> bool:+ if error.status in _RETRYABLE_RPC_STATUSES:+ return True+ return any(phrase in error.message for phrase in _RETRYABLE_RPC_MESSAGES)+async def _with_transient_rpc_retry(operation: Callable[[], Awaitable[T]],@@ -78,7 +91,7 @@ async def _with_transient_rpc_retry(return await operation()except RPCError as e:attempt += 1- if attempt >= max_attempts or e.status not in _RETRYABLE_RPC_STATUSES:+ if attempt >= max_attempts or not _is_retryable_rpc_error(e):raisebackoff = min(2 * attempt, 30)logger.debug(diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/temporalio/test_temporalio.py b/products/warehouse_sources/backend/temporal/data_imports/sources/temporalio/test_temporalio.pyindex bfc91cea0b83..34b59daf5d37 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/temporalio/test_temporalio.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/temporalio/test_temporalio.py@@ -111,6 +111,9 @@ class TestTransientRPCRetry:[("namespace rate limit exceeded", RPCStatusCode.RESOURCE_EXHAUSTED),("downstream duration timeout", RPCStatusCode.DEADLINE_EXCEEDED),+ # A mid-stream HTTP/2 transport interruption surfaces as UNKNOWN, not one of the+ # transient statuses above — it must still be ridden out in-process.+ ("h2 protocol error: error reading a body from connection", RPCStatusCode.UNKNOWN),],)@patch(@@ -154,13 +157,21 @@ class TestTransientRPCRetry:# Bounded attempts leave Temporal to retry; backs off between attempts but not after the last.assert sleep.await_args_list == [call(2), call(4), call(6)]+ @pytest.mark.parametrize(+ "message,status",+ [+ ("workflow execution not found for", RPCStatusCode.NOT_FOUND),+ # UNKNOWN alone must not be retried — only UNKNOWN carrying a transport signature is.+ ("internal server error", RPCStatusCode.UNKNOWN),+ ],+ )@patch("products.warehouse_sources.backend.temporal.data_imports.sources.temporalio.temporalio.asyncio.sleep",new_callable=AsyncMock,)- async def test_non_transient_rpc_error_is_not_retried(self, sleep):+ async def test_non_transient_rpc_error_is_not_retried(self, sleep, message, status):async def operation():- raise _rpc_error("workflow execution not found for", RPCStatusCode.NOT_FOUND)+ raise _rpc_error(message, status)with pytest.raises(RPCError):await _with_transient_rpc_retry(operation, MagicMock())