Skip to content

Bug 2091129 - Bugzilla::DB pings MySQL before every query (about 200 pings per show_bug.cgi request) - #2821

Merged
dklawren merged 6 commits into
mozilla:masterfrom
dklawren:2091129
Nov 12, 2026
Merged

dklawren merged 6 commits into
mozilla:masterfrom
dklawren:2091129

Conversation

@dklawren

@dklawren dklawren commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the request-scoped database-handle caching change.

No open issues 🎉

What changed in this PR

Reduces repeated database connection checks in Bugzilla by reusing checked handles instead of consulting DBIx::Connector before every query.

Changes:

  • Caches database handles per request, rechecking after five seconds, a process ID change, or handle inactivity.
  • Adds tests for handle reuse, request boundaries, interval expiry, simulated process ID changes, and reconnection after disconnect.
File Description
t/​db-dbh-check.t Tests connection-check frequency and handle revalidation.
Bugzilla/​DB.pm Replaces delegated handle access with request-scoped caching and periodic checks.

Review effort: Balanced

@dklawren
dklawren requested review from Xzzz and cgsheeh November 10, 2026 00:05
Comment thread Bugzilla/DB.pm Outdated
$cache->{refaddr $self} = {dbh => $dbh, pid => $PID, checked => $now};
return $dbh;
}
has [qw(dsn user pass attrs)] => (is => 'ro', required => 1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: should there be a blank line here, or should sub dbh move below the has declarations so the attributes stay grouped together?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved sub dbh (along with DBH_CHECK_INTERVAL and its comment) below the has/around declarations in 5db4dc0, so the attributes are grouped together.

Comment thread Bugzilla/DB.pm
use constant DBH_CHECK_INTERVAL => 5;

# DBIx::Connector->dbh pings the server on every call, and every proxied DBI
# method below calls dbh(), so a single page used to send hundreds of pings.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment above the DBI proxy methods (lines 86-87, DBIx::Connector->dbh has to be called each time we need a DBI handle to ensure the connection is alive) now says the opposite of this change.

Could it be updated, for example with something like "We can't use handles() as dbh() has to re-check the connection (see dbh above)"? As you want, its a detail ;)

@Xzzz Xzzz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good to me, thanks!
Just a suggestion on a comment line, but not so important :)

@dklawren
dklawren merged commit 6273f0a into mozilla:master Nov 12, 2026
13 of 14 checks passed
@dklawren
dklawren deleted the 2091129 branch November 12, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants