Re: This connection has been closed

From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: Magosányi Árpád <mag(at)magwas(dot)rulez(dot)org>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: This connection has been closed
Date: 2011-12-06 06:52:15
Message-ID: CA+0W9LMVMvVh84ztm5CQVvSRj0N85kFGRN4Sv834DEuRm7Q-yA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On 6 December 2011 19:10, Magosányi Árpád <mag(at)magwas(dot)rulez(dot)org> wrote:
> I am using a cdo server (org.eclipse.emf.cdo) which uses hibernate which
> uses the postgresql jdbc driver. (9.0.0.801)
> Between two transactions the tcp connection between the cdo server and
> postgresql went down (my laptop hibernated).
> I got an exception with this cause:
>
> Caused by: org.postgresql.util.PSQLException: This connection has been
> closed.
>    at
> org.postgresql.jdbc2.AbstractJdbc2Connection.checkClosed(AbstractJdbc2Connection.java:714)
>    at
> org.postgresql.jdbc2.AbstractJdbc2Connection.getAutoCommit(AbstractJdbc2Connection.java:680)
>    at
> org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:127)
>    at
> org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
>
> This might be related to this issue:
> https://forum.hibernate.org/viewtopic.php?f=1&t=957369
>
> Do we have a hibernate, a postgresql or a CDO issue here?

In general you'll only get that exception in two cases:

1) You call Connection.close(); then you try to use the connection again
2) You try to do something on a Connection that requires I/O, there
is an I/O error (e.g. TCP connection failure), the driver throws a
suitable SQLException and implicitly closes the connection; then you
try to use the connection again.

I would guess that it is case (2) happening here. Presumably something
isn't treating the first exception as fatal, and then you get the
"connection is closed" exception when you later try to reuse the
connection.

You can detect this by looking for an 08-class SQLState error code in
the thrown exception; or if you're using the driver's
ConnectionPoolDataSource implementation, it'll fire a
connectionErrorOccurred callback when the driver decides the
connection is dead.

(Ideally we'd implement the exception subclasses present in 1.6 i.e..
SQLNonTransientConnectionException, but backwards compatibility is a
bit messy there)

Oliver

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Samuel Gendler 2011-12-06 07:55:12 Re: This connection has been closed
Previous Message John R Pierce 2011-12-06 06:15:49 Re: This connection has been closed