Skip to content

GCS clients are never closed, leaking sockets until the process runs out of file descriptors #394

Open

Description

@aliu65803

Type: bug
Area: GCS client lifecycle (io_utils/fsutil/impl_gcs.py, io_utils/fsutil/generic.py)

Found on: NVIDIA/kumo-engine main @ cce65cec13b6. Reproduced against a deployed
backend image tagged 3.0.11, Kubernetes v1.30.5, Linux x86_64, driven by
kumoai==3.0.0b3. The image tag has no matching tag in this repo, so the built commit
is not pinned; line references below are from cce65cec13b6.

Related: #372 is the same errno in the DiskGraph path, driven by shard count. This is a
socket leak in the blob-storage client, so the two are independent.

Problem

GCS clients are created per worker thread and never closed. Their sockets accumulate in
CLOSE_WAIT until the process runs out of file descriptors, after which any new
connection fails — ingest, graph snapshots, connector validation. The process does not
recover; it stays wedged until restarted.

The leak is cumulative with total transfer volume, not with how parallel the work is.

Mechanism:

  1. impl_gcs.py:84 — ThreadLocalGCSClient(threading.local) gives each thread its own
    storage.Client, constructed lazily at :125 and cached on that thread.
  2. generic.py:474-489 — _copy_files_with_scoped_threads() opens a new
    ThreadPoolExecutor per call, so every copy() creates a fresh set of worker
    threads (up to 32).
  3. Each new thread therefore builds a new storage.Client with its own HTTP connection
    pool.
  4. When the executor exits, the threads and their thread-local storage go away, but
    nothing calls close() on the client or its transport, so the sockets are never
    released. _reset() at :128 clears the reference but also closes nothing.

Each copy() can therefore leak up to 32 clients' worth of connections, and the total
only grows.

Evidence

The process pinned at the limit with no jobs running:

open fds:   1023 / 1024
sockets:    1012
CLOSE_WAIT:  998

CLOSE_WAIT means the remote end closed and the application never did. All the leaked
sockets point at the Google APIs endpoint range:

199.36.153.4:443   199.36.153.5:443
199.36.153.6:443   199.36.153.7:443

Monotonic growth across one day of ingest activity, on a pod with 0 restarts:

390 -> 441 -> 531 -> 1023    (never drains; sampled repeatedly at the ceiling)

Other services in the namespace show the same pattern at smaller scale, so this is not
one bad call site:

databackend  CLOSE_WAIT=998
kumo-api     CLOSE_WAIT=120
mlworkflow   CLOSE_WAIT=10
kumo-rest    CLOSE_WAIT=0

User-visible failures

While descriptors last, ingest fails per table:

OSError: [Errno 24] Failed to open local file
  '/mnt/localssd/local-ingest/source-reader/<run>/part-00168-00000.parquet'
  Detail: [errno 24] Too many open files

How many tables fail depends on how much work has already run, which makes it look like
a data problem with particular tables:

run tables failed
A 3 of 20
B 7 of 20
C 1 of 20

Once descriptors are exhausted, failures stop mentioning files at all, because sockets
cannot be opened either:

NewConnectionError: HTTPSConnection(host='storage.googleapis.com', port=443):
  Failed to establish a new connection: [Errno 24] Too many open files
ConnectorError: BigQuery connection validation timed out

The BigQuery message is not a timeout — there was no descriptor available to open the
connection. At that point graph.snapshot() returns
422: Unable to prepare all table refreshes; please retry, and retrying cannot help.

Reproduce

  1. Run repeated copy() operations against GCS (any cold multi-table ingest will do).
  2. Watch ls /proc/1/fd | wc -l grow and never fall, with
    cat /proc/1/net/tcp | awk '$4=="08"' | wc -l (CLOSE_WAIT) growing alongside.
  3. At the soft limit, ingest fails with errno 24. Afterwards every operation needing a
    new connection fails, including graph snapshots and connector validation.

The ceiling is reached by cumulative transfers, so a small ingest repeated often
reproduces this as surely as one large ingest.

Suggested fix

  1. Close the clients. Give storage.Client a defined lifetime — close it and its
    transport session when the owning thread retires, or hold one long-lived client and
    share it instead of constructing one per thread.
  2. Stop churning threads. _copy_files_with_scoped_threads() builds a new pool per
    call; reusing a pool would stop minting a fresh client for every copy.
  3. Raising the soft nofile limit is not a fix — with an unbounded leak, any fixed
    limit is eventually reached. It only changes how long the service lasts before it
    wedges.

#395 covers the error reporting that made this hard to diagnose: the surfaced message
names tables and tells the user to check their data sources, with no errno anywhere.

Activity

  1. added
    bug
    on Nov 18, 2026
  2. changed the title [-]Cold multi-table ingest exhausts file descriptors[/-] [+]GCS clients are never closed, leaking sockets until the process runs out of file descriptors[/+] on Nov 18, 2026
  3. aliu65803 commented on Nov 18, 2026

    @aliu65803
    ContributorAuthor

    Rewritten — the original version of this issue attributed the descriptor exhaustion to
    unbounded staging concurrency (N_tables x 32 in-flight transfers). That was wrong.

    What ruled it out: the process sits at 1023/1024 descriptors with no jobs running,
    998 of them sockets in CLOSE_WAIT, and the count never drains. Concurrency was zero at
    the time of measurement, so concurrency cannot be the cause. The largest copy batch
    observed was only 2,840 files, which 32 workers handle comfortably when sockets are
    released.

    The actual cause is a leak: clients are constructed per worker thread and never closed,
    and the thread pool is rebuilt on every copy(). Exhaustion therefore tracks cumulative
    transfer volume, not parallelism — which also explains why the number of failing tables
    varied between otherwise identical runs.

    This matters for the fix: the original issue suggested raising the soft nofile limit as
    a mitigation. With an unbounded leak that only delays the wedge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdata-platform

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions