Close stale JDBC connection before replacing it on db.properties reload #164

Merged
tobi merged 1 commit from close-stale-connection-on-db-properties-reload into main 2026-09-06 08:43:59 +00:00
Owner

Fixes #163.

DbSource.getConnection() opens a replacement connection whenever db.properties has been modified since it was last read (fileUpdated), but the branch also fires when the currently cached connection is still open and healthy — in that case the old connection was discarded and overwritten in the cache (tx.registerConnection(...) / connection.set(...)) without ever being closed. Every thread that still held a live connection to that DbSource at the moment of the reload leaked one open socket.

This adds an explicit close of the stale connection, guarded so it only runs when there actually is one to close (the con == null and con.isClosed() cases already have nothing to close).

Note: #161 / PR #162 chased a different, incorrect diagnosis (worker-thread idle timeout) — that path already closes connections correctly via the finally block in RequestEvaluator.run(), in place since 2005. Both are closed; this is the real fix.

Fixes #163. `DbSource.getConnection()` opens a replacement connection whenever `db.properties` has been modified since it was last read (`fileUpdated`), but the branch also fires when the currently cached connection is still open and healthy — in that case the old connection was discarded and overwritten in the cache (`tx.registerConnection(...)` / `connection.set(...)`) without ever being closed. Every thread that still held a live connection to that `DbSource` at the moment of the reload leaked one open socket. This adds an explicit close of the stale connection, guarded so it only runs when there actually is one to close (the `con == null` and `con.isClosed()` cases already have nothing to close). Note: #161 / PR #162 chased a different, incorrect diagnosis (worker-thread idle timeout) — that path already closes connections correctly via the `finally` block in `RequestEvaluator.run()`, in place since 2005. Both are closed; this is the real fix.
tobi self-assigned this 2026-09-06 07:56:49 +00:00
Close stale JDBC connection before replacing it on db.properties reload
All checks were successful
Build / build (push) Successful in 28s
616dda14e5
Fixes #163.

DbSource.getConnection() opens a replacement connection whenever
db.properties has been modified since it was last read, but discarded
the previously cached connection without closing it first when that
connection was still open and healthy. Every thread holding a live
connection to the DbSource at the moment of the reload leaked one
socket.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VDE7nDf1nSCMsaB68zjeWF
Author
Owner

Tested live on antville-dev (ct 3080): deployed this branch via the 'Deploy' workflow (hostname: antville-test.de), then reproduced the exact sequence that shows the bug — warm up a connection, touch db.properties, wait past the 1.5s ResourceProperties cache window, make another request.

Before this fix (on the unpatched build), that sequence grew the connection count 2→3, leaving the old connection orphaned alongside the new one. With this build (helma-26.9.6.jar), it's a clean 1-for-1 swap both times I ran it — old port gone, new port in its place, connection count never grows, thread count steady at 30 throughout.

Merging.

Tested live on antville-dev (ct 3080): deployed this branch via the 'Deploy' workflow (`hostname: antville-test.de`), then reproduced the exact sequence that shows the bug — warm up a connection, touch `db.properties`, wait past the 1.5s `ResourceProperties` cache window, make another request. Before this fix (on the unpatched build), that sequence grew the connection count 2→3, leaving the old connection orphaned alongside the new one. With this build (`helma-26.9.6.jar`), it's a clean 1-for-1 swap both times I ran it — old port gone, new port in its place, connection count never grows, thread count steady at 30 throughout. Merging.
tobi merged commit 063190eb9c into main 2026-09-06 08:43:59 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
antville/helma!164
No description provided.