Bug 294035 - ctld can accumulate zombie children
Summary: ctld can accumulate zombie children
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 15.0-STABLE
Hardware: amd64 Any
: --- Affects Some People
Assignee: John Baldwin
URL:
Keywords:
: 295211 (view as bug list)
Depends on:
Blocks:
 
Reported: 2026-03-25 00:52 UTC by Nikolay Denev
Modified: 2026-06-26 17:29 UTC (History)
3 users (show)

See Also:
linimon: mfc-stable15?
linimon: mfc-stable14?


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nikolay Denev 2026-03-25 00:52:10 UTC
`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");
                        }
```
Comment 1 John Baldwin freebsd_committer freebsd_triage 2026-04-02 18:30:40 UTC
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.
Comment 2 commit-hook freebsd_committer freebsd_triage 2026-04-20 17:21:09 UTC
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(-)
Comment 3 John Baldwin freebsd_committer freebsd_triage 2026-05-15 16:08:15 UTC
*** Bug 295211 has been marked as a duplicate of this bug. ***
Comment 4 commit-hook freebsd_committer freebsd_triage 2026-06-23 16:29:11 UTC
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(-)