COPY: leaked lock on connection drop

From: Maciek Sakrejda <msakrejda(at)truviso(dot)com>
To: PG-JDBC Mailing List <pgsql-jdbc(at)postgresql(dot)org>
Subject: COPY: leaked lock on connection drop
Date: 2011-06-01 02:36:21
Message-ID: BANLkTimRR-zyjCiQ_MzTQLETCe3zLGLixQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

This is something of a degenerate error, but it's worth documenting on
the list, if nothing else.

Take the following scenario:

1. JDBC user starts COPY, COPY acquires query execution lock in
QueryExecutorImpl
2. Connection dies, and writeToCopy gets an IOException; note that
query execution lock is not released
3. User catches exception; attempts to use the connection again (e.g.,
to issue a ROLLBACK)
4. The driver waits indefinitely on the query execution lock

I have not confirmed this, but the query execution lock management
that was put in for COPY does not seem to account for exception
handling in the QueryExecutorImpl.

As far as I can see, this is never a problem in normal operation--only
when the connection dies. A potential workaround is to use
getSQLState() to check the type of error, and only attempt to use the
connection if it's still live.

The proper fix would be to manage locking and unlocking more carefully
with respect to exception handling.

---
Maciek Sakrejda | System Architect | Truviso

1065 E. Hillsdale Blvd., Suite 215
Foster City, CA 94404
(650) 242-3500 Main
www.truviso.com

Browse pgsql-jdbc by date

  From Date Subject
Next Message Michal Politowski 2011-06-01 13:06:49 Mixed up protocol packets in server response?
Previous Message Oliver Jowett 2011-06-01 00:53:27 Re: "postgresql-9.0-801.jdbc4.jar" Causing "Error committing transaction. Cause: org.postgresql.util.PSQLException: Cannot commit when autoCommit is enabled." Exception