• Post Reply Bookmark Topic Watch Topic
  • New Topic

org.postgresql.util.PSQLException: This connection has been closed.  RSS feed

 
Jagadeeswar Hemadribhotla
Greenhorn
Posts: 5
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting the following exceptions while logging in to my application. I have tried to figure it out but its being hard to find a solution. Please suggest a way to resolve.

 
Dave Tolls
Ranch Foreman
Posts: 3011
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

    at com.myapp.utils.DataBaseConnection.getStatement(DataBaseConnection.java:117)
    at com.myapp.utils.DataBaseUtils.execute(DataBaseUtils.java:190)


Can you show us the code around here?
I have a suspicion you are holding onto Connection objects in your utility after they've been closed and are attempting to reuse them.
 
Tim Holloway
Bartender
Posts: 18781
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I read the stack correctly, you're trying to obtain a connection from a Tomcat database connection pool, but the pool connection is closed and therefore useless.

This can happen with a lot of databases where idle connections timeout (and close themselves) if they are not used often enough.

There are options for Tomcat pools that can deal with this, either by "pinging" the connections to keep them alive or by discarding dead ones and creating new replacements. Check the Tomcat docs for details.
 
Dave Tolls
Ranch Foreman
Posts: 3011
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The tomcat connection pool handles that by checking whether the connection is alive or not.
At least it has done for a long time now.

As I said, to me that stack trace seems to imply someone holding onto a connection in their utility class, which you should not do.
 
Tim Holloway
Bartender
Posts: 18781
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, unless default behaviour has changed, the Tomcat connection pool does not do a liveness check by default. Then again, Tomcat 8 switched to a different pool manager, so the documentation should be checked.

I re-read the stack trace and it's possible that a proxied JDBC call is being done rather than a pool fetch. If that's so, my money is on someone having stored a pool Connection object in their session - which, of course, one should never do. Connection is an Interface, and thus not serializable. These days, Tomcat is supposed to reject non-serializable HttpSession objects, but I'm sure there are cases that it doesn't catch.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!