Search code examples
databaseeclipsetomcatconnectionterminate

Database connection leak when terminating (Not stopping) tomcat on eclipse


It was as hard to write a good title for this issue as it was to search the web for it.

I have a lot of projects, some are in maintenance (they have been productive for years) and others in active development. This is an important fact because the problem happens on all projects on my computer and not on others.

The problem is that I run all web projects on tomcat and they all have database connections. I always used the "Terminate" button in favor of the "Stop" button to restart or stop tomcat from eclipse.

For those who dont know, the terminate button is the red button that stops the app from the log console or the debug console, while the stop button is the same red button but on the servers console.

It is a lot faster to stop the servers from the terminate button rather then the stop button, the problem is that ever since I upgraded to Helios my database connections no longer closed when terminating the servers... they do when stopping them normally.

Well no need to say that I discovered this because the database servers (Oracle, MySQL and SQLServer) started giving "Too many connections" errors.

This is a huge head scratcher for me since code has nothing to do with this issue, different types of database management in different projects have the same problem, only on my machine! Yes I havee tried this on other computers and the problem does not occur.

I have tried everything I could think of short from formatting...

  • Upgraded to Indigo
  • Reinstalled Galileo (even downloaded a fresh copy)
  • Reinstalled and tried different databases
  • Tried different versions of Tomcat (6 and 7)

I am starting to think it might not be an IDE problem and it just happened to start when I upgraded eclipse.

ANY suggestions are welcome!


Solution

  • When you stop Tomcat using that red button, Tomcat is actually requested to stop itself. If some SQL statement of your webapplication is blocked, then Tomcat will not stop. This probably causes the connection leak.

    Why would an SQL statement block? This typically happens if another database user updates or deletes the same record that your application is trying to update/modify.

    However, in my case Eclipse shows a popup after about 30 seconds to warn that Tomcat did not stop itself. The popup asks whether Tomcat should then be terminated (which should terminate even while the blocked connectione exists).