Re: How do I determine the origin of database connection pool leaks?
Rob Sargent <[email protected]>
| Newsgroups | gmane.comp.jakarta.tomcat.user |
|---|---|
| Message-ID | <[email protected]> |
> On Nov 16, 2025, at 3:52 AM, Graham Leggett <[email protected]> wrote: > > Hi all, > > I have a tomcat9 web application that is leaking connections, and I need to detect where the leaks are occurring. This is surprisingly difficult. > > The leak is reproducible, and occurs in a controlled test environment, so the vast majority of advice out there about monitoring database connections isn't useful - I know there is a leak. The codebase is large, so the "look at the codebase" advice doesn't work. > > The exceptions I get tell me all about the straw that broke the camel's back, but none of that is useful - what I need to know at that point is what else is on the camel's back. > > Is there a mechanism that exists where you can trigger a dump of the stack traces of all database connections currently open and where they were opened? Remember - in my case this is a reproducible leak in a controlled test environment, so I don't have the problem of a live system or filtering out noise. > > This isn't working for me, I see no stack traces related to abandoned connections: > > <Resource auth="Container" driverClassName="org.postgresql.Driver" factory="org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory" logAbandoned="true" maxIdle="5" maxTotal="5" maxWaitMillis="10000" name="" password="" type="javax.sql.DataSource" url="" username="" removeAbandonedOnBorrow="true" removeAbandoned="true" removeAbandonedTimeout="10" /> > > Is there a breakpoint I can stop the code at, or a signal I can send? > So the code base is opening connections and not closing them. Assuming this is a java environment you might need to wrap every connection call in a “try-with-resource” block to get a guaranteed close. Can you narrow your tests to find the culprit(s)? > Regards, > Graham > -- >