DbSource leaks the previous JDBC connection when db.properties is touched #163
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
DbSource.getConnection()opens a replacement JDBC connection wheneverdb.propertieshas been modified since it was last read, but discards the previously cached connection without closing it — leaking one open socket per thread that still held a live connection to thatDbSourceat the time.Where
src/main/java/helma/objectmodel/db/DbSource.java,getConnection():When
fileUpdatedis true but the cachedconis still open and healthy (notnull, notisClosed()), this branch still runs: it opens a brand-newConnectionviaDriverManager.getConnection()and overwrites the cache entry —tx.registerConnection(this, con)replaces whateverTransactor.sqlConnectionsheld for thisDbSource, andconnection.set(con)does the same for the non-TransactorThreadLocalpath. Neither branch closes the connection being replaced. Nothing else references it afterward, so it stays open on the database side until the driver's finalizer runs (unreliable) or the server's ownwait_timeouteventually kills it.This is distinct from #161 (closed, wrong diagnosis) — worker-thread idle timeout is already handled correctly via the
finally { tx.closeConnections(); }block wrappingrun()'s outer loop. This leak instead fires on every thread that still holds a live connection to a givenDbSourceat the moment itsdb.propertiesis next read as modified — one leaked connection per such thread, per file touch.Suggested fix
Close the stale connection before replacing it: