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-imports): stop reporting delta watermark fd-exhaustion as a bug (#102806)

Tom Owerscbd0b02c5285
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/errors.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/errors.py
index 6b2eea168ba4..8d4f8944904e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/errors.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/errors.py
@@ -148,14 +148,30 @@ def is_invalid_version_race(error: BaseException) -> bool:
return type(error) is deltalake.exceptions.DeltaError and DELTA_INVALID_VERSION_RACE_NEEDLE in str(error)
+def _is_too_many_open_files_error(error: BaseException) -> bool:
+ """True if opening the app-DB connection failed because this worker is out of file descriptors.
+
+ `update_sync_type_config_keys` (persisting the vacuum watermark) opens a fresh Django connection;
+ its socket/selector setup raises a bare `OSError` — not a psycopg exception — when `socket()` hits
+ EMFILE (this process's fd table is full) or ENFILE (the system-wide table is full), before libpq
+ has anything to wrap into `OperationalError`. Same transient fd-pressure condition already handled
+ for the source's own connect path (`postgres.py::_is_too_many_open_files_error`) and for
+ `cdp_producer.py`'s own-DB check: a descriptor frees the moment another connection/handle in this
+ worker closes, so it's never a customer or maintenance-logic problem.
+ """
+ return isinstance(error, OSError) and error.errno in (errno.EMFILE, errno.ENFILE)
+
+
def is_transient_maintenance_error(error: BaseException) -> bool:
"""Infra blips seen during delta maintenance that aren't a maintenance bug.
Covers S3/object-store hiccups reaching our own data-warehouse bucket (see
`is_transient_object_store_error` above), racy concurrent-maintenance DeltaErrors (see
- `is_transient_delta_maintenance_error` above), and app-DB connection blips (DNS, pooler drops) hit
- while resolving `job.folder_path()` on a pooled connection — the same `OperationalError`/`InterfaceError`
- classification used for this failure class in `repartition_table.py`'s `_is_transient_infra_error`.
+ `is_transient_delta_maintenance_error` above), and app-DB connection blips (DNS, pooler drops, fd
+ exhaustion) hit while resolving `job.folder_path()` or persisting the vacuum watermark on a pooled
+ connection — the same `OperationalError`/`InterfaceError` classification used for this failure class
+ in `repartition_table.py`'s `_is_transient_infra_error`, plus `_is_too_many_open_files_error` above
+ for the fd-exhaustion variant that reaches here as a bare `OSError`.
Also covers a primary-DB failover briefly routing the watermark's `select_for_update()` onto a
connection that has become a read-only standby: Postgres raises `ReadOnlySqlTransaction`
@@ -167,4 +183,6 @@ def is_transient_maintenance_error(error: BaseException) -> bool:
return True
if isinstance(error, InternalError) and isinstance(error.__cause__, psycopg.errors.ReadOnlySqlTransaction):
return True
+ if _is_too_many_open_files_error(error):
+ return True
return is_transient_object_store_error(error) or is_transient_delta_maintenance_error(error)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_delta_errors.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_delta_errors.py
index 28bc327a0b49..0df65763835b 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_delta_errors.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_delta_errors.py
@@ -202,6 +202,14 @@ class TestIsTransientMaintenanceError:
True,
),
("genuine_bug", RuntimeError("maintenance blew up"), False),
+ # The watermark-persist connect (`update_sync_type_config_keys`) raises a bare OSError,
+ # not an OperationalError, when this worker's own fd table is full — same condition
+ # `postgres.py::_is_too_many_open_files_error` already retries on the source's connect path.
+ ("watermark_persist_emfile", OSError(errno.EMFILE, "Too many open files"), True),
+ ("watermark_persist_enfile", OSError(errno.ENFILE, "Too many open files in system"), True),
+ # An OSError with an unrelated errno (e.g. a real permissions problem) must not be swept
+ # up by the fd-exhaustion check just because it shares the exception type.
+ ("unrelated_os_error_wrong_errno", OSError(errno.EACCES, "Permission denied"), False),
# A primary failover briefly turns the write connection into a read-only standby mid
# watermark-persist — Postgres raises ReadOnlySqlTransaction (25006), which psycopg
# classifies under InternalError rather than OperationalError.