Close JDBC connections before releasing an idled-out worker thread #162

Closed
tobi wants to merge 1 commit from close-jdbc-connections-on-idle-timeout into main
Owner

Fixes #161.

RequestEvaluator.notifyAndWait() nulled thread/transactor on the InterruptedException and idle-timeout paths without first calling tx.closeConnections(), unlike every other exit path in the class (the finally in run(), stopTransactor(), and the “another thread already took over” branch earlier in the same method). The cached JDBC connection then had nothing telling the driver to close its socket, so it stayed open until the driver's own finalizer ran (unreliable) or the database's wait_timeout closed it server-side — one leaked connection per idled-out worker thread.

This adds the same Transactor.getInstance() / closeConnections() call already used elsewhere in the file to both gap branches. No other behavior changes.

See the issue for the production evidence (245+ idle MariaDB connections against 55 live OS threads on a long-running instance) and why this also covers scheduled/cron jobs, which route through the same RequestEvaluator/Transactor machinery via CronRunner → invokeInternal().

Fixes #161. `RequestEvaluator.notifyAndWait()` nulled `thread`/`transactor` on the `InterruptedException` and idle-timeout paths without first calling `tx.closeConnections()`, unlike every other exit path in the class (the `finally` in `run()`, `stopTransactor()`, and the “another thread already took over” branch earlier in the same method). The cached JDBC connection then had nothing telling the driver to close its socket, so it stayed open until the driver's own finalizer ran (unreliable) or the database's `wait_timeout` closed it server-side — one leaked connection per idled-out worker thread. This adds the same `Transactor.getInstance()` / `closeConnections()` call already used elsewhere in the file to both gap branches. No other behavior changes. See the issue for the production evidence (245+ idle MariaDB connections against 55 live OS threads on a long-running instance) and why this also covers scheduled/cron jobs, which route through the same `RequestEvaluator`/`Transactor` machinery via `CronRunner` → `invokeInternal()`.
tobi self-assigned this 2026-09-05 08:29:55 +00:00
Close JDBC connections before releasing an idled-out worker thread
All checks were successful
Build / build (push) Successful in 34s
6c972a88f7
RequestEvaluator.notifyAndWait() nulled thread/transactor on the
InterruptedException and idle-timeout paths without first calling
tx.closeConnections(), unlike every other exit path in the class. The
cached connection then stayed open until the driver's own finalizer
ran or the database's wait_timeout closed it server-side, leaking one
connection per idled-out worker thread.

Fixes #161

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Author
Owner

Closing without merging — this was on the wrong track. See the comment on #161: tx.closeConnections() already runs for both the InterruptedException and idle-timeout exits, via the finally block wrapping run()'s outer loop (in place since 2005, well before the currently deployed helma-20190209.jar). A live test on antville-dev confirmed connections clear correctly on idle timeout even without this change.

The actual leak is filed as #163, fix incoming in a separate PR.

Closing without merging — this was on the wrong track. See the comment on #161: `tx.closeConnections()` already runs for both the `InterruptedException` and idle-timeout exits, via the `finally` block wrapping `run()`'s outer loop (in place since 2005, well before the currently deployed `helma-20190209.jar`). A live test on antville-dev confirmed connections clear correctly on idle timeout even without this change. The actual leak is filed as #163, fix incoming in a separate PR.
tobi closed this pull request 2026-09-06 07:55:49 +00:00
All checks were successful
Build / build (push) Successful in 34s

Pull request closed

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!162
No description provided.