From a8202f96e0c4a7dcafe770a5377b029f95382ff0 Mon Sep 17 00:00:00 2001 From: Marc van der Wal Date: Tue, 21 Jul 2026 10:59:20 +0200 Subject: [PATCH 1/3] Do not reuse DB handles in child processes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both the test agent and RPC API fork child processes from a common parent. The parent process may connect to the database and if that happens, the child process may reuse the connection that was initiated by the parent. However, this causes mayhem in the test agent. While the parent process uses the DB connection to check for new tests to carry out, the child processes use that same DB connection to update the test progress and store the results. DB connection handles aren’t meant to be used concurrently, so subtle problems can happen in this situation. It also causes mayhem in the RPCAPI because the common parent makes a connection before forking the worker children. Each child therefore shares the same connection handle concurrently, which can also cause the same subtle problems in production. The solution is to ensure that database connection handles are always tied to a specific PID. In Zonemaster::Backend::DB, this check is done whenever the dbh() method is called: if the current PID is not the same as the PID that created the database connection, we return a new connection. --- lib/Zonemaster/Backend/DB.pm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/Zonemaster/Backend/DB.pm b/lib/Zonemaster/Backend/DB.pm index c2376f35..0c731f28 100644 --- a/lib/Zonemaster/Backend/DB.pm +++ b/lib/Zonemaster/Backend/DB.pm @@ -56,6 +56,12 @@ has 'dbhandle' => ( required => 1, ); +has 'dbhandlepid' => ( + is => 'rw', + isa => 'Maybe[Int]', + required => 0, +); + =head2 $REQUIRED_SCHEMA_VERSION A positive integer. The database schema version that this module is compatible with. @@ -135,7 +141,10 @@ sub get_db_class { sub dbh { my ( $self ) = @_; - if ( $self->dbhandle && $self->dbhandle->ping ) { + # Do not return the DB handle if it belongs to a different process: we + # might have forked and be in the child process. If we are not careful, we + # might be messing with someone else's database connection! + if ( $self->dbhandle && $self->dbhandle->ping && $self->dbhandlepid && $self->dbhandlepid == $$ ) { return $self->dbhandle; } @@ -162,6 +171,7 @@ sub dbh { ); $self->dbhandle( $dbh ); + $self->dbhandlepid( $$ ); return $self->dbhandle; } From 3ed180873a4bccdb6b0c5cf1681f36a1f04a98ff Mon Sep 17 00:00:00 2001 From: Mats Dufberg Date: Tue, 21 Jul 2026 16:27:04 +0000 Subject: [PATCH 2/3] Preparation for release v2026.1.1 --- Changes | 7 +++++++ lib/Zonemaster/Backend.pm | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index 93791831..9bdf6f4c 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,13 @@ Release history for Zonemaster component Zonemaster-Backend +v12.1.1 2026-07-22 (part of Zonemaster v2026.1.1 release) + + [Fixes] + - Prevents DB handles to be reused in child processes, + resolves a bug introduced in previous release (#1256) + + v12.1.0 2026-06-29 (part of Zonemaster v2026.1 release) [Release information] diff --git a/lib/Zonemaster/Backend.pm b/lib/Zonemaster/Backend.pm index 003d60eb..1167bdb7 100644 --- a/lib/Zonemaster/Backend.pm +++ b/lib/Zonemaster/Backend.pm @@ -1,6 +1,6 @@ package Zonemaster::Backend; -our $VERSION = '12.1.0'; +our $VERSION = '12.1.1'; use strict; use warnings; From 3e0eaab8188d00cb749677cae776bb2f841a510b Mon Sep 17 00:00:00 2001 From: Mats Dufberg Date: Wed, 22 Jul 2026 10:48:30 +0200 Subject: [PATCH 3/3] Update Changes Co-authored-by: tgreenx <96772376+tgreenx@users.noreply.github.com> --- Changes | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index 9bdf6f4c..e03697af 100644 --- a/Changes +++ b/Changes @@ -4,8 +4,8 @@ Release history for Zonemaster component Zonemaster-Backend v12.1.1 2026-07-22 (part of Zonemaster v2026.1.1 release) [Fixes] - - Prevents DB handles to be reused in child processes, - resolves a bug introduced in previous release (#1256) + - Prevents DB handles to be reused in child processes (#1256); + a regression introduced in the previous release v12.1.0 2026-06-29 (part of Zonemaster v2026.1 release)