`ctld` can leave exited child processes in `<defunct>` state for a long time even though the parent daemon remains alive and continues listening for new connections. It appears the SIGCHLD interrupts the kevent() but not the outer loop where the child reaping happens, they can accumulate. This can be reproduced by connecting to any port where ctld is listening, e.g. nvmeof discovery or iscsi. I believe this should fix the issue by returning from main_loop() and having wait_for_children() run: ``` diff --git a/usr.sbin/ctld/ctld.cc b/usr.sbin/ctld/ctld.cc index 331c029e28..a6c80a3604 100644 --- a/usr.sbin/ctld/ctld.cc +++ b/usr.sbin/ctld/ctld.cc @@ -2418,7 +2418,7 @@ main_loop(bool dont_fork) error = kevent(kqfd, NULL, 0, &kev, 1, NULL); if (error == -1) { if (errno == EINTR) - continue; + return; log_err(1, "kevent"); } ```
Mmm, it looks like I broke this when switching to kevent as it was a return before when using select. I don't really like having the logic split up with the two nested loops (one in main_loop() and one in main()) and maybe someday we can refactor this, but this is fine for now.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=e56687bb2d32ee4b1774300f3960427ca56b34bb commit e56687bb2d32ee4b1774300f3960427ca56b34bb Author: Nikolay Denev <ndenev@gmail.com> AuthorDate: 2026-04-20 17:18:50 +0000 Commit: John Baldwin <jhb@FreeBSD.org> CommitDate: 2026-04-20 17:18:50 +0000 ctld: Return from the inner "main" loop on EINTR This ensures that child processes are reaped in the outer loop in main(). PR: 294035 Reviewed by: asomers Fixes: 66b107e82b2f ("ctld: Use kevent(2) for socket events rather than select(2)") Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D56525 usr.sbin/ctld/ctld.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
*** Bug 295211 has been marked as a duplicate of this bug. ***
A commit in branch stable/15 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=0efab2ba4c0017c28d21efca76a7947eb7a2f087 commit 0efab2ba4c0017c28d21efca76a7947eb7a2f087 Author: Nikolay Denev <ndenev@gmail.com> AuthorDate: 2026-04-20 17:18:50 +0000 Commit: John Baldwin <jhb@FreeBSD.org> CommitDate: 2026-06-23 16:05:31 +0000 ctld: Return from the inner "main" loop on EINTR This ensures that child processes are reaped in the outer loop in main(). PR: 294035 Reviewed by: asomers Fixes: 66b107e82b2f ("ctld: Use kevent(2) for socket events rather than select(2)") Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D56525 (cherry picked from commit e56687bb2d32ee4b1774300f3960427ca56b34bb) usr.sbin/ctld/ctld.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)