[Bug Report + Patch] File descriptor leak when io_method=io_uring

Lucas DRAESCHER <git@draescher.fr>

From: Lucas DRAESCHER <git@draescher.fr>
To: "pgsql-hackers@lists.postgresql.org" <pgsql-hackers@lists.postgresql.org>
Date: 2026-03-18T15:11:13Z
Lists: pgsql-hackers

Attachments

Hello Hackers,

I noticed a file descriptor leak when running PostgreSQL 18 with
io_method=io_uring. As far as I could tell, it only triggers when
the server restarts due to one of the backends being killed.

How to reproduce the issue:
- Setup a server configured with io_uring
- Check the number of open file descriptors:
    ls -la "/proc/$(head -1 $PGDATA/postmaster.pid)/fd/" | grep "io_uring" | wc -l
- SIGKILL a backend to trigger a server restart:
    kill -9 $(psql -XtA -U postgres -c "SELECT pid FROM pg_stat_activity WHERE backend_type = 'client backend' LIMIT 1")
- Check the number of open files descriptors again:
    Expected: FD count remains the same.
    Actual: FD count has doubled.

Tested on PostgreSQL 18.0, 18.1, 18.2, 18.3 and git master on the
following platforms:
- Ubuntu Server 24.04: Linux 6.8.0, liburing 2.5
- Exherbo Linux: Linux 6.16.12, liburing 2.12
- Fedora Linux: Linux 6.19.7, liburing 2.13-dev

From what I could gather, this happens because 
pgaio_uring_shmem_init() in 
src/backend/storage/aio/method_io_uring.c doesn't cleanup 
the allocated resources on exit.

I've attached a patch which registers an on_shmem_exit() callback 
to close the file descriptors on server exit. I took inspiration
from how src/backend/storage/aio/method_worker.c handles cleanup.

Regards,

Lucas.

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Fix LATERAL references in GRAPH_TABLE with multi-label pattern