Bug 284282 - ctld rewrites its pidfile too often
Summary: ctld rewrites its pidfile too often
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 15.0-CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-01-22 23:04 UTC by Alan Somers
Modified: 2025-02-05 19:56 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alan Somers freebsd_committer freebsd_triage 2025-01-22 23:04:46 UTC
ctld rewrites its pidfile in the main_loop function.  And it will exit and reenter that function every time that select gets interrupted by EINTR due to SIGCHLD.  That will happen whenever a child process exits, and that will happen every time it gets a new connection attempt.

On a production server, I saw that ctld was rewriting its pidfile about 20 times per second, due to a misconfigured iSCSI client that kept trying to connect to a nonexistent target over and over.  Yet when the pidfile didn't exist, a concurrent "service ctld reload" would fail.  Such a failure would cause higher level code to restart ctld, which can cause various other problems.

To prevent the need to restart ctld unnecessarily, the pidfile open/close logic should be moved out of main_loop and into main.
Comment 1 commit-hook freebsd_committer freebsd_triage 2025-02-05 19:56:27 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=7bad3c3e5f1c8b4d9e620bb2943299d4a30f3c86

commit 7bad3c3e5f1c8b4d9e620bb2943299d4a30f3c86
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2025-02-05 19:53:14 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2025-02-05 19:55:16 +0000

    ctld: Write the pidfile once after forking

    Don't rewrite the pidfile each time main_loop is called.

    PR:             284282
    Reported by:    asomers
    Reviewed by:    asomers
    Sponsored by:   Chelsio Communications
    Differential Revision:  https://reviews.freebsd.org/D48768

 usr.sbin/ctld/ctld.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)