[Bug] Possible io_uring FD leak across crash recovery

From: Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>
Subject: [Bug] Possible io_uring FD leak across crash recovery
Date: 2026-09-14 18:52:58
Message-ID: CAJTYsWVn1hXNGezogW5iEqROkdQ7Q2i1yrpeFV1QdWjgJyYaDw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I think I ran into an io_uring FD leak while chasing the CFBot failures
for the no-core PANIC patch [1]. Both Linux Meson jobs in [2] use
io_method=io_uring and hit this after several deliberate crashes:

FATAL: could not setup io_uring queue: Too many open files
HINT: Consider increasing "ulimit -n" to at least 1132.

To rule out the test hook, I also tried killing an ordinary backend
with SIGKILL and waiting for recovery each time. With io_method=io_uring
and ulimit -n 1024, I saw the following ring FD counts in the postmaster.
Its PID stayed the same throughout:

initial: 142
recovery 1: 284
recovery 2: 426
recovery 3: 568
recovery 4: 710
recovery 5: 852
recovery 6: 994
recovery 7: failed with EMFILE

AFAICS, pgaio_uring_shmem_init() creates a fresh set of rings each time
the postmaster reinitializes shmem. I couldn't find a matching
io_uring_queue_exit() for the old set. The postmaster is still alive,
so those FDs would stick around.

FWIW, I tried adding an on_shmem_exit callback to call
io_uring_queue_exit() for the initialized rings. With that change, the
postmaster's io_uring FD count stayed at 142 through ten crash/recovery
cycles.

Am I missing an existing cleanup path here?

[1]
https://www.postgresql.org/message-id/CAJTYsWV601xS0D_SrZ111VX0N%2BtRe2fjK-VjY75v1gNJ93%2BjkQ%40mail.gmail.com
[2] https://github.com/postgres/postgres-cfbot/actions/runs/34815719686

Regards,
Ayush

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2026-09-14 19:01:27 Re: Translation of the NextOID message in pg_controldata
Previous Message Peter Eisentraut 2026-09-14 18:48:24 Re: Trying out <stdatomic.h>