From debbugs-submit-bounces@debbugs.gnu.org Fri Apr 11 17:37:43 2025 Received: (at submit) by debbugs.gnu.org; 11 Apr 2025 21:37:43 +0000 Received: from localhost ([127.0.0.1]:52031 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1u3M4F-0002dv-3m for submit@debbugs.gnu.org; Fri, 11 Apr 2025 17:37:43 -0400 Received: from lists.gnu.org ([2001:470:142::17]:35036) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1u3M4C-0002de-Fu for submit@debbugs.gnu.org; Fri, 11 Apr 2025 17:37:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u3M45-0000tP-Vu for guix-patches@gnu.org; Fri, 11 Apr 2025 17:37:34 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u3M44-0008F4-1c; Fri, 11 Apr 2025 17:37:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=JlqY/d4sm/47+oaQEJhf3IISpxdXckaMSAFAqzsrdzg=; b=o06LuC5dYAk5Gj wx+ACUiHg0Dxo5Sm2mU3nEfJvcbm4vdNcTTbIjDAmI2SbeP8yBulZZ1+KiIMqM0t06EnoPAdl9Poe smPnyCu0sznjPzv2DD2bC/OkKZIjD7sz9jySGoOz8BuA46jGAM+49HBM35g5YKOQ8O5cT0/9zqPfF hlj0ULFfXOO1oYsYfg2ZtuaLTalibeXjgwrK9OgP1NXleCxzfYhnfMC4LAMdps3pvCjUFztaR3dMr mUa8GpGZ1cUC0VIQRLKMFNPR1rNPQqANChsLtLoaY6/9A7dXxfP1jLMpHqMu2P7yfbafracw/1w32 23fQT2iKzhejOEYfZ8hg==; From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= To: guix-patches@gnu.org Subject: [PATCH] daemon: Catch SIGINT, SIGTERM, and SIGHUP for proper termination. Date: Fri, 11 Apr 2025 23:37:20 +0200 Message-ID: <1385cb8951405f364ae02b9c36eb6e33ea204afa.1744407289.git.ludo@gnu.org> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: submit Cc: =?UTF-8?q?Ludovic=20Court=C3=A8s?= , Christopher Baines X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Previously the daemon would not install handlers for these signals. It would thus terminate abruptly when receiving them, without properly closing the SQLite database. Consequently, the database’s WAL file, which is normally deleted by the last client closing the database (via ‘sqlite3_close’), would not be deleted when the guix-daemon process is terminated; instead, it would persist and possibly keep growing beyond reason. This patch fixes that. * nix/nix-daemon/nix-daemon.cc (handleSignal, setTerminationSignalHandler): New functions. (processConnection): Call it. Reported-by: Christopher Baines Change-Id: I07e510a1242e92b6a629d60eb840e029c0f921be --- nix/nix-daemon/nix-daemon.cc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) Hello, While discussing it with Maxim and Chris on guix-sysadmin, we realized that the daemon was not always properly closing its database, which was a likely explanation of its WAL file not being deleted and growing too much on the build farm. This patch appears to fix that. Thoughts? Ludo’. diff --git a/nix/nix-daemon/nix-daemon.cc b/nix/nix-daemon/nix-daemon.cc index 4cb05c802e..e29237e65d 100644 --- a/nix/nix-daemon/nix-daemon.cc +++ b/nix/nix-daemon/nix-daemon.cc @@ -165,6 +165,24 @@ static void setSigPollAction(bool enable) #endif } +static void handleSignal(int signum) +{ + string name = program_invocation_short_name; + auto message = name + ": PID " + std::to_string(getpid()) + + " caught signal " + std::to_string(signum) + "\n"; + writeFull(STDERR_FILENO, (unsigned char *) message.c_str(), message.length()); + _isInterrupted = 1; + blockInt = 1; +} + +static void setTerminationSignalHandler() +{ + auto signals = { SIGINT, SIGTERM, SIGHUP }; + for (int signum: signals) { + signal(signum, handleSignal); + } +} + /* startWork() means that we're starting an operation for which we want to send out stderr to the client. */ @@ -803,6 +821,10 @@ static void processConnection(bool trusted, uid_t userId) throw Error("if you run `nix-daemon' as root, then you MUST set `build-users-group'!"); #endif + /* Catch SIGTERM & co. to ensure proper termination: closing the store + and its database, thereby deleting its WAL file. */ + setTerminationSignalHandler(); + /* Open the store. */ store = std::shared_ptr(new LocalStore(reserveSpace)); base-commit: 772b70455d0d5972fdad80d8529647dce20f409a -- 2.49.0 From debbugs-submit-bounces@debbugs.gnu.org Mon Apr 14 17:07:50 2025 Received: (at 77753-done) by debbugs.gnu.org; 14 Apr 2025 21:07:50 +0000 Received: from localhost ([127.0.0.1]:49278 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1u4R1y-0001wy-3j for submit@debbugs.gnu.org; Mon, 14 Apr 2025 17:07:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40344) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1u4R1v-0001we-9e for 77753-done@debbugs.gnu.org; Mon, 14 Apr 2025 17:07:47 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u4R1n-0005aJ-UQ; Mon, 14 Apr 2025 17:07:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=G2bMK0fi92d/5UEFqoJEUHRDo/WYQUp2YRG3EDYuI4s=; b=LNB8Xe6/HoxUkdvtc2Wr fmlwi6oCVoG1/i5UMwVauI0894HuA25JgK78nvLPtvSNp+ui3MO6J/01fN5z3Dzuoxg0+VrTe5WnM lVhPDNYa4uAOsxz+C751n6xYulBJlrFlJQldazm3ArIs69oaHyLiOnsbEndTMReUFabav0x4i74w3 Ckm0nP1nsZ8W5kuXn7cdbhJE/qDq8OsVzylnRHoLJGgpXHcA4SGYVn4KM92wIUa4m1AO/QwRmwbfn FyV8xwxHpWL87dLd/P+QotLddmjdIjGGJ02MlI7uCeNm9SIJzRc8T6aDJPnfGvoS+ZBF9z7+f/k3N gIXbjZjCCHyF5g==; From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: 77753-done@debbugs.gnu.org Subject: Re: [bug#77753] [PATCH] daemon: Catch SIGINT, SIGTERM, and SIGHUP for proper termination. In-Reply-To: <1385cb8951405f364ae02b9c36eb6e33ea204afa.1744407289.git.ludo@gnu.org> ("Ludovic =?utf-8?Q?Court=C3=A8s=22's?= message of "Fri, 11 Apr 2025 23:37:20 +0200") References: <1385cb8951405f364ae02b9c36eb6e33ea204afa.1744407289.git.ludo@gnu.org> Date: Mon, 14 Apr 2025 23:07:25 +0200 Message-ID: <87v7r6laeq.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 77753-done Cc: Christopher Baines X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Ludovic Court=C3=A8s writes: > Previously the daemon would not install handlers for these signals. It > would thus terminate abruptly when receiving them, without properly > closing the SQLite database. > > Consequently, the database=E2=80=99s WAL file, which is normally deleted = by the > last client closing the database (via =E2=80=98sqlite3_close=E2=80=99), w= ould not be > deleted when the guix-daemon process is terminated; instead, it would > persist and possibly keep growing beyond reason. > > This patch fixes that. > > * nix/nix-daemon/nix-daemon.cc (handleSignal, setTerminationSignalHandler= ): > New functions. > (processConnection): Call it. > > Reported-by: Christopher Baines > Change-Id: I07e510a1242e92b6a629d60eb840e029c0f921be Pushed as dd947985522886f9de6fdfdde3f0601e42219da5. From unknown Fri Sep 19 13:25:07 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Tue, 13 May 2025 11:24:16 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator