: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(postgres): tell users to re-enable a sync stopped by an SSH gateway failure (#105845)
Tom Owersb23125ab0683
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.pyindex 73702169ba02..b1ba9aa97399 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py@@ -294,11 +294,16 @@ _FOREIGN_SERVER_UNREACHABLE_ERROR = (# down, or its firewall blocks PostHog's IPs. The raw message tells the user nothing actionable, so# replace it with concrete guidance on both the validate and sync paths._SSH_GATEWAY_SESSION_ERROR = "Could not establish session to SSH gateway"-_SSH_GATEWAY_UNREACHABLE_MESSAGE = (+_SSH_GATEWAY_UNREACHABLE_GUIDANCE = ("Could not connect to your SSH tunnel — PostHog couldn't open a session to the SSH gateway. ""Check that the SSH host and port point to a reachable SSH server (not the database port), that "- "the bastion is running, and that PostHog's IP addresses are allowed through its firewall."+ "the bastion is running, and that PostHog's IP addresses are allowed through its firewall")+_SSH_GATEWAY_UNREACHABLE_MESSAGE = f"{_SSH_GATEWAY_UNREACHABLE_GUIDANCE}."+# The sync path classifies this non-retryable, which switches the schema off, so the customer has+# to turn it back on once the bastion is reachable again — the setup path has no sync to re-enable.+# Mirrors `_SSH_HANDSHAKE_EOF_ERROR` below, the same gateway-configuration class.+_SSH_GATEWAY_UNREACHABLE_SYNC_MESSAGE = f"{_SSH_GATEWAY_UNREACHABLE_GUIDANCE}, then re-enable the sync."# A source past the SSL cutoff connects with sslmode=require, so a server built without SSL support# fails the moment the sync — or a direct query — opens its connection. An SSH tunnel with@@ -868,7 +873,7 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa),"SSLRequiredError": None,"SSL/TLS connection is required": None,- _SSH_GATEWAY_SESSION_ERROR: _SSH_GATEWAY_UNREACHABLE_MESSAGE,+ _SSH_GATEWAY_SESSION_ERROR: _SSH_GATEWAY_UNREACHABLE_SYNC_MESSAGE,# paramiko raises a bare, message-less EOFError when the SSH gateway accepts the TCP# connection but drops it mid-handshake (a non-SSH service on the port, the bastion# refusing PostHog's IPs, a proxy resetting the stream). sshtunnel doesn't wrap it, sodiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.pyindex dbbd87dfbd1f..c64d90cc6b96 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py@@ -540,6 +540,21 @@ class TestPostgresSourceNonRetryableErrors:assert "re-enable the sync" in matches[0].lower()assert "db.example.com" not in matches[0]+ def test_ssh_gateway_session_failure_tells_the_customer_to_re_enable(self, source):+ # This entry is non-retryable, so matching it switches the schema off. Without the+ # re-enable step the customer fixes the bastion and the sync stays silently stopped.+ # Mirror the finalizer's first-match selection so a reorder that shadows it with an+ # earlier None-valued key is caught.+ error_msg = "BaseSSHTunnelForwarderError: Could not establish session to SSH gateway"+ matches = [+ friendly+ for pattern, friendly in source.get_non_retryable_errors().items()+ if error_message_matches(error_msg, [pattern])+ ]+ assert matches, "an unreachable SSH gateway must be classified non-retryable"+ assert matches[0] is not None, "an unreachable SSH gateway must surface an actionable message"+ assert "re-enable the sync" in matches[0].lower()+@pytest.mark.parametrize(("error_msg", "reason_code", "expected_word"),[