[libpostgresql-jdbc-java] 04/09: Fix a deadlock that occurs when retrieving notifications. Normal query execution enters the QueryExecutor monitor and then calls a synchronized method in the ProtocolConnection to update the transaction state. Notification retrieval operates in the reverse order, entering the ProtocolConnection monitor and then calling a synchronized method in the QueryExecutor.

Emmanuel Bourg ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:20:14 UTC 2017


This is an automated email from the git hooks/post-receive script.

ebourg-guest pushed a commit to tag REL8_1_413
in repository libpostgresql-jdbc-java.

commit 7ac56511872fc881825b3f326cd1ad24fd373b11
Author: Kris Jurka <books at ejurka.com>
Date:   Tue Apr 1 07:19:46 2008 +0000

    Fix a deadlock that occurs when retrieving notifications.  Normal
    query execution enters the QueryExecutor monitor and then calls a
    synchronized method in the ProtocolConnection to update the
    transaction state.  Notification retrieval operates in the reverse
    order, entering the ProtocolConnection monitor and then calling a
    synchronized method in the QueryExecutor.
    
    Remove the QueryExecutor call from ProtocolConnection and make the
    higher level code responsible for calling it so we always acquire
    locks in the same order.
    
    Report and diagnosis by Joao Rui Leal.
---
 org/postgresql/core/QueryExecutor.java             | 11 ++++++++++-
 org/postgresql/core/v2/ProtocolConnectionImpl.java |  3 +--
 org/postgresql/core/v3/ProtocolConnectionImpl.java |  3 +--
 org/postgresql/jdbc2/AbstractJdbc2Connection.java  |  3 ++-
 4 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/org/postgresql/core/QueryExecutor.java b/org/postgresql/core/QueryExecutor.java
index b6fc3a2..58fbe08 100644
--- a/org/postgresql/core/QueryExecutor.java
+++ b/org/postgresql/core/QueryExecutor.java
@@ -4,7 +4,7 @@
 * Copyright (c) 2004, Open Cloud Limited.
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/core/QueryExecutor.java,v 1.39 2005/01/11 08:25:43 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/core/QueryExecutor.java,v 1.40 2005/02/01 07:27:53 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -170,6 +170,15 @@ public interface QueryExecutor {
      */
     Query createParameterizedQuery(String sql); // Parsed for parameter placeholders ('?')
 
+    /**
+     * Prior to attempting to retrieve notifications, we need to pull
+     * any recently received notifications off of the network buffers.
+     * The notification retrieval in ProtocolConnection cannot do this
+     * as it is prone to deadlock, so the higher level caller must be
+     * responsible which requires exposing this method.
+     */
+    void processNotifies() throws SQLException;
+
     //
     // Fastpath interface.
     //
diff --git a/org/postgresql/core/v2/ProtocolConnectionImpl.java b/org/postgresql/core/v2/ProtocolConnectionImpl.java
index b09a1b0..898ab58 100644
--- a/org/postgresql/core/v2/ProtocolConnectionImpl.java
+++ b/org/postgresql/core/v2/ProtocolConnectionImpl.java
@@ -4,7 +4,7 @@
 * Copyright (c) 2004, Open Cloud Limited.
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/core/v2/ProtocolConnectionImpl.java,v 1.7 2005/06/21 18:07:09 davec Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/core/v2/ProtocolConnectionImpl.java,v 1.7.2.1 2005/12/02 03:06:03 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -57,7 +57,6 @@ class ProtocolConnectionImpl implements ProtocolConnection {
     }
 
     public synchronized PGNotification[] getNotifications() throws SQLException {
-        executor.processNotifies();
         PGNotification[] array = (PGNotification[])notifications.toArray(new PGNotification[notifications.size()]);
         notifications.clear();
         return array;
diff --git a/org/postgresql/core/v3/ProtocolConnectionImpl.java b/org/postgresql/core/v3/ProtocolConnectionImpl.java
index eedffed..15d28ee 100644
--- a/org/postgresql/core/v3/ProtocolConnectionImpl.java
+++ b/org/postgresql/core/v3/ProtocolConnectionImpl.java
@@ -4,7 +4,7 @@
 * Copyright (c) 2004, Open Cloud Limited.
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/core/v3/ProtocolConnectionImpl.java,v 1.8 2005/06/21 18:07:09 davec Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/core/v3/ProtocolConnectionImpl.java,v 1.8.2.1 2005/12/02 03:06:04 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -58,7 +58,6 @@ class ProtocolConnectionImpl implements ProtocolConnection {
     }
 
     public synchronized PGNotification[] getNotifications() throws SQLException {
-        executor.processNotifies();
         PGNotification[] array = (PGNotification[])notifications.toArray(new PGNotification[notifications.size()]);
         notifications.clear();
         return array;
diff --git a/org/postgresql/jdbc2/AbstractJdbc2Connection.java b/org/postgresql/jdbc2/AbstractJdbc2Connection.java
index 5828529..5de6002 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2Connection.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2Connection.java
@@ -3,7 +3,7 @@
 * Copyright (c) 2004-2005, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Connection.java,v 1.32.2.2 2007/12/01 09:17:59 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Connection.java,v 1.32.2.3 2008/02/19 06:12:50 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -965,6 +965,7 @@ public abstract class AbstractJdbc2Connection implements BaseConnection
 
     public PGNotification[] getNotifications() throws SQLException
     {
+        getQueryExecutor().processNotifies();
         // Backwards-compatibility hand-holding.
         PGNotification[] notifications = protoConnection.getNotifications();
         return (notifications.length == 0 ? null : notifications);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git



More information about the pkg-java-commits mailing list