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(data-warehouse): name Railway's proxy when it closes a sync's connection (#113478)

Tom Owers7ff1a5c6b332
diff --git a/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py b/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py
index 988dd8de22c2..35f70fe54dcd 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py
@@ -301,7 +301,31 @@ SYNC_RUN_STALLED_MESSAGE = (
# Unlike `Any_Source_Errors` above, matching here only rewrites the stored message: the error stays
# retryable and the schema stays enabled. Keys are the same stable, host-free fragments the sources
# already classify these conditions by, so they can't collide with a customer value.
+# A source reached over Railway's TCP proxy. A driver names the endpoint it dialled in the
+# connection-drop message, as the host it resolved and the address behind it, so the proxy is
+# identifiable from the error text without reading the source config. Both markers belong to the
+# TCP proxy alone: `.rlwy.net` is the domain it hands out, and `66.33.22.0/24` is the address range
+# it resolved to as of October 2026, matched because customers paste the address as often as the
+# host name. A Railway-hosted HTTP API is `*.up.railway.app` and matches neither, so a REST source
+# behind one keeps the copy for its own failure.
+RAILWAY_PROXY_ENDPOINT_MARKERS = (".rlwy.net", "66.33.22.")
+
+
+# Specialises TRANSIENT_SOURCE_CONNECTION_MESSAGE for that proxy. The generic copy asks the customer
+# to look for a pooler, a firewall or an SSH tunnel ending the connection, and on Railway the thing
+# in front of the source is none of those, so it sends them looking for something they cannot find.
+RAILWAY_PROXY_CONNECTION_MESSAGE = (
+ "PostHog's connection to your source kept closing before the sync could finish. This host is "
+ "Railway's TCP proxy, which closes connections when the service behind it is asleep or out of "
+ "connection slots. In Railway, check that the service is running, and check its connection "
+ "limit. This sync is still enabled and will run again on its next schedule."
+)
+
+
Transient_Error_Messages: dict[str, str] = {
+ # Before the generic connection-drop copy below, because first match wins and this one names
+ # the cause. Railway's own host strings, which libpq prints in the connection-drop message.
+ **dict.fromkeys(RAILWAY_PROXY_ENDPOINT_MARKERS, RAILWAY_PROXY_CONNECTION_MESSAGE),
# libpq/psycopg losing an established connection, at connect or mid-stream, in every wording
# `_CONNECTION_DROPPED_ERROR_SUBSTRINGS` (postgres.py) retries in-process first.
"server closed the connection unexpectedly": TRANSIENT_SOURCE_CONNECTION_MESSAGE,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/tests/test_external_data_job_activities.py b/products/warehouse_sources/backend/temporal/data_imports/tests/test_external_data_job_activities.py
index 30bc0b41b70e..3448299bcaa3 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/tests/test_external_data_job_activities.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/tests/test_external_data_job_activities.py
@@ -18,6 +18,7 @@ from products.warehouse_sources.backend.models.external_data_schema import Exter
from products.warehouse_sources.backend.models.external_data_source import ExternalDataSource
from products.warehouse_sources.backend.temporal.data_imports.external_data_job import (
CANCELLED_RUN_MESSAGE,
+ RAILWAY_PROXY_CONNECTION_MESSAGE,
SYNC_RUN_STALLED_MESSAGE,
SYNC_RUN_TOO_LONG_MESSAGE,
TRANSIENT_EGRESS_MESSAGE,
@@ -396,6 +397,30 @@ def test_read_only_transaction_disables_the_schema_only_when_the_source_raised_i
"503 Server Error: Service Temporarily Unavailable for url: https://api.example.com/v1/things",
TRANSIENT_VENDOR_UNAVAILABLE_MESSAGE,
),
+ # Railway's TCP proxy, which the generic connection-drop copy would otherwise claim. Both
+ # shapes are matched, because a customer configures either the proxy host or its address.
+ (
+ "railway_proxy_by_host",
+ ExternalDataSourceType.POSTGRES,
+ 'connection failed: connection to server at "test.proxy.rlwy.net" (198.51.100.7), '
+ "port 31234 failed: server closed the connection unexpectedly",
+ RAILWAY_PROXY_CONNECTION_MESSAGE,
+ ),
+ (
+ "railway_proxy_by_address",
+ ExternalDataSourceType.POSTGRES,
+ 'connection failed: connection to server at "66.33.22.7", port 31234 failed: '
+ "server closed the connection unexpectedly",
+ RAILWAY_PROXY_CONNECTION_MESSAGE,
+ ),
+ # Railway's HTTP domain is not its TCP proxy, so a REST source hosted on Railway keeps the
+ # copy for its own failure rather than being told to check a connection limit.
+ (
+ "railway_hosted_rest_api",
+ ExternalDataSourceType.APPLESEARCHADS,
+ "503 Server Error: Service Temporarily Unavailable for url: https://api.up.railway.app/v1/things",
+ TRANSIENT_VENDOR_UNAVAILABLE_MESSAGE,
+ ),
]
)
@pytest.mark.django_db(transaction=True)