[Bug] Possible io_uring FD leak across crash recovery

Started by Ayush Tiwari3 months ago2 messageshackers

Thread notes

1 note#bug
hackorum-bot#bug
hackorum-bot
2 days ago

@global #bug

#bug
Jump to latest
#1Ayush Tiwari
ayushtiwari.slg01@gmail.com

Hi,

I think I ran into an io_uring FD leak while chasing the CFBot failures
for the no-core PANIC patch [1]/messages/by-id/CAJTYsWV601xS0D_SrZ111VX0N+tRe2fjK-VjY75v1gNJ93+jkQ@mail.gmail.com. Both Linux Meson jobs in [2]https://github.com/postgres/postgres-cfbot/actions/runs/34815719686 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]: /messages/by-id/CAJTYsWV601xS0D_SrZ111VX0N+tRe2fjK-VjY75v1gNJ93+jkQ@mail.gmail.com
/messages/by-id/CAJTYsWV601xS0D_SrZ111VX0N+tRe2fjK-VjY75v1gNJ93+jkQ@mail.gmail.com
[2]: https://github.com/postgres/postgres-cfbot/actions/runs/34815719686

Regards,
Ayush

#2cca5507
cca5507@qq.com
In reply to: Ayush Tiwari (#1)
Re: [Bug] Possible io_uring FD leak across crash recovery

Hi,

Am I missing an existing cleanup path here?

There is a CF entry for this bug:

https://commitfest.postgresql.org/patch/6617/

--
Regards,
ChangAo Chen