Обсуждение: [Bug Report + Patch] File descriptor leak when io_method=io_uring

Поиск
Список
Период
Сортировка

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

От
Lucas DRAESCHER
Дата:
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.

Вложения

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

От
"cca5507"
Дата:
Hi,

Thanks for the report! I can reproduce this bug on master and your patch fixes it.

> 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.

I also verify that only the postmaster will call this callback because all children
of the postmaster will reset postmaster's callback.

My another thought is that add a shmem_cleanup callback to IoMethodOps and
do cleanup in this callback. Not sure which is better.

--
Regards,
ChangAo Chen

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

От
Lucas DRAESCHER
Дата:
Hi ChangAo,

Thanks for the review!

I've attached v2, which adds a shmem_cleanup callback to
IoMethodOps, registered in AioShmemInit().

Like you, I don't know which approach I prefer since the
new callback currently has only one implementor. If no
other IO method is expected to need cleanup, the simpler
v1 approach may be preferable. Happy to hear your thoughts.

I've also added this patch to the commitfest app:
https://commitfest.postgresql.org/patch/6617/

Regards,
Lucas.
Вложения

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

От
Lucas DRAESCHER
Дата:
I have attached v3 which rebases v2 on top of master.

v1 still applies cleanly.

Regards,

Lucas
Вложения