diff --git a/Changes b/Changes index 93791831..e03697af 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 (#1256); + a regression introduced in the previous release + + 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; 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; }