Skip to content

: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.

fix(temporal): treat EAI_AGAIN Redis DNS failures as transient (#113651)

Tom Owersa9e292cd49d3
diff --git a/posthog/temporal/common/posthog_client.py b/posthog/temporal/common/posthog_client.py
index b2c2b5c420d0..f89f28f2e15b 100644
--- a/posthog/temporal/common/posthog_client.py
+++ b/posthog/temporal/common/posthog_client.py
@@ -20,6 +20,7 @@ from posthog.temporal.common.db_errors import is_transient_db_error
from posthog.temporal.common.errors import NonReportableError
from posthog.temporal.common.interceptor import ALL_TASK_QUEUES
from posthog.temporal.common.logger import get_write_only_logger
+from posthog.temporal.common.redis_errors import is_transient_redis_error
from posthog.temporal.common.shutdown import WorkerShuttingDownError
logger = get_write_only_logger()
@@ -65,7 +66,7 @@ def is_expected_activity_failure(error: BaseException) -> bool:
already records via record_outbound_decision), errors explicitly marked non-reportable
(expected customer/upstream conditions, e.g. a REST API serving a login page instead of JSON),
expected-control-flow ApplicationErrors (activity-retry-as-poll probes), and a saturated or
- restarting database that clears on its own.
+ restarting database or Redis instance that clears on its own.
The activity interceptor below re-raises these without reporting them. An activity that also
captures locally must apply the same filter, or a worker drain mints an error tracking issue
@@ -79,6 +80,7 @@ def is_expected_activity_failure(error: BaseException) -> bool:
and error.type in EXPECTED_CONTROL_FLOW_ERROR_TYPES
)
or is_transient_db_error(error)
+ or is_transient_redis_error(error)
)
@@ -136,6 +138,12 @@ class _PostHogClientActivityInboundInterceptor(ActivityInboundInterceptor):
activity.info().activity_type,
exc_info=e,
)
+ elif is_transient_redis_error(e):
+ await logger.awarning(
+ "Transient Redis error in activity %s, leaving retry to Temporal",
+ activity.info().activity_type,
+ exc_info=e,
+ )
raise
activity_info = activity.info()
capture_kwargs = {
diff --git a/posthog/temporal/common/redis_errors.py b/posthog/temporal/common/redis_errors.py
new file mode 100644
index 000000000000..293be7ca6b01
--- /dev/null
+++ b/posthog/temporal/common/redis_errors.py
@@ -0,0 +1,30 @@
+import redis.exceptions
+
+# getaddrinfo EAI_AGAIN (errno -3): the resolver could not get an answer right now, for example
+# during a short cluster DNS outage. It clears when DNS comes back, so a Temporal retry self-heals.
+# EAI_NONAME ("Name or service not known") and EAI_NODATA ("No address associated with hostname")
+# stay unmatched, because both can mean a host that never resolves — a real misconfiguration that
+# must keep reaching error tracking. Mirrors the equivalent Postgres marker in db_errors.py.
+_TRANSIENT_REDIS_ERROR_MARKERS = ("Temporary failure in name resolution",)
+
+# Count the raised error toward the limit so cyclic or very long chains stay bounded.
+_MAX_CAUSE_CHAIN_DEPTH = 10
+
+
+def is_transient_redis_error(error: BaseException) -> bool:
+ """Check this error and its explicit causes for a transient Redis connectivity failure.
+
+ Only a connect-time ConnectionError/TimeoutError whose message matches a marker above
+ qualifies — a refused connection or a bad password is a real defect, not a DNS blip, and
+ must keep reaching error tracking. Ignores `__context__`: an unrelated failure inside an
+ `except` block must stay reportable.
+ """
+ for _ in range(_MAX_CAUSE_CHAIN_DEPTH):
+ if isinstance(error, redis.exceptions.ConnectionError | redis.exceptions.TimeoutError):
+ message = str(error)
+ if any(marker in message for marker in _TRANSIENT_REDIS_ERROR_MARKERS):
+ return True
+ if error.__cause__ is None:
+ break
+ error = error.__cause__
+ return False
diff --git a/posthog/temporal/common/test_redis_errors.py b/posthog/temporal/common/test_redis_errors.py
new file mode 100644
index 000000000000..3c7e839a1091
--- /dev/null
+++ b/posthog/temporal/common/test_redis_errors.py
@@ -0,0 +1,67 @@
+import pytest
+
+import redis.exceptions
+from temporalio.exceptions import ApplicationError
+
+from posthog.temporal.common.redis_errors import is_transient_redis_error
+
+
+def _raised_from(error: BaseException, cause: BaseException) -> BaseException:
+ error.__cause__ = cause
+ return error
+
+
+ "error,expected",
+ [
+ (ValueError("Temporary failure in name resolution"), False),
+ (
+ redis.exceptions.ConnectionError(
+ "Error -3 connecting to redis-example:6379. Temporary failure in name resolution."
+ ),
+ True,
+ ),
+ (redis.exceptions.TimeoutError("Timeout connecting to server: Temporary failure in name resolution"), True),
+ # A host that never resolves is a real misconfiguration, not a blip — must keep reaching
+ # error tracking.
+ (
+ redis.exceptions.ConnectionError("Error -2 connecting to redis-example:6379. Name or service not known."),
+ False,
+ ),
+ # A refused connection or bad auth is a real defect, not a DNS blip.
+ (redis.exceptions.ConnectionError("Error 111 connecting to redis-example:6379. Connection refused."), False),
+ (redis.exceptions.AuthenticationError("invalid username-password pair"), False),
+ # An activity that re-raises one typed error keeps the drop in __cause__ only.
+ (
+ _raised_from(
+ ApplicationError("Failed to check billing limits"),
+ redis.exceptions.ConnectionError(
+ "Error -3 connecting to redis-example:6379. Temporary failure in name resolution."
+ ),
+ ),
+ True,
+ ),
+ ],
+)
+def test_is_transient_redis_error_by_message(error: BaseException, expected: bool) -> None:
+ assert is_transient_redis_error(error) is expected
+
+
[email protected]("suppress_context", [False, True])
+def test_is_transient_redis_error_ignores_context(suppress_context: bool) -> None:
+ error = KeyError("team_id")
+ error.__context__ = redis.exceptions.ConnectionError(
+ "Error -3 connecting to redis-example:6379. Temporary failure in name resolution."
+ )
+ error.__suppress_context__ = suppress_context
+
+ assert not is_transient_redis_error(error)
+
+
[email protected]("cycle_length", [1, 2])
+def test_is_transient_redis_error_handles_cyclic_causes(cycle_length: int) -> None:
+ errors = [ValueError("not a redis error") for _ in range(cycle_length)]
+ for index, error in enumerate(errors):
+ error.__cause__ = errors[(index + 1) % cycle_length]
+
+ assert not is_transient_redis_error(errors[0])