Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 733226324C1 for ; Wed, 24 Feb 2010 04:11:08 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 72150-01 for ; Wed, 24 Feb 2010 08:10:54 +0000 (UTC) X-Greylist: delayed 00:36:18.592491 by SQLgrey-1.7.6 Received: from mail-pv0-f174.google.com (mail-pv0-f174.google.com [74.125.83.174]) by mail.postgresql.org (Postfix) with ESMTP id 9A983632482 for ; Wed, 24 Feb 2010 04:10:57 -0400 (AST) Received: by pvb32 with SMTP id 32so771980pvb.19 for ; Wed, 24 Feb 2010 00:10:56 -0800 (PST) MIME-Version: 1.0 Received: by 10.142.55.10 with SMTP id d10mr4186795wfa.244.1266995534084; Tue, 23 Feb 2010 23:12:14 -0800 (PST) Date: Tue, 23 Feb 2010 23:12:14 -0800 Message-ID: <895e58dd1002232312r2a937a9blb7d380ba64afd57d@mail.gmail.com> Subject: synchronization problems with COPY on connection failure From: Maciek Sakrejda To: PG-JDBC Mailing List Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.289 tagged_above=-10 required=5 tests=AWL=0.310, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201002/45 X-Sequence-Number: 20332 As a heads up to anyone that may be using COPY, we ran into some problems with COPY synchronization on connection failure. I'm not quite sure how extensive they are yet, but here's the sequence that causes a problem: 1. Start a COPY IN query 2. Break the connection (I'm not quite sure if you need to break the network connection or just bring down PostgreSQL; I think either should work but I'm not positive) 3. Cancel the COPY. This will try to send a CopyFail to the backend, but get a SocketException and propagate it wrapped in a PSQLException 4. Catch the exception, and try to execute a query This will hang on waitOnLock() in QueryExecutorImpl, since the failing cancelCopy() never released its lock (the long-lived COPY lock) on the connection. This is typically reset on an RFQ, except that in this case, there are no more RFQs because the connection is dead. So a ghost COPY lock is held by a failed COPY operation, and most other connection operations will block indefinitely. A workaround is to check the exception cause and avoid further queries if the connection is borked, but since failing to do that leads to a hung thread, it would be nice to have more robust behavior here. Unfortunately, moving the current COPY synchronization mechanism to something more robust would take some doing (I tried before in attempting to resolve the Terminate-during-COPY issue), and the RFQ-based unlocking is a reasonable approach 99.9% of the time. A possible approach would be to keep the current synchronization mechanism, but release locks on connection failure. All COPY operations already handle IOExceptions specially, so I think this would be a fairly minor change. Any thoughts? Thanks, --- Maciek Sakrejda | Software Engineer | Truviso 1065 E. Hillsdale Blvd., Suite 230 Foster City, CA 94404 (650) 242-3500 Main (650) 242-3501 F www.truviso.com