[libpostgresql-jdbc-java] 04/11: 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:32 UTC 2017
This is an automated email from the git hooks/post-receive script.
ebourg-guest pushed a commit to tag REL8_2_509
in repository libpostgresql-jdbc-java.
commit abe6ebb207f4e20868e915dcfccaca42f99a7982
Author: Kris Jurka <books at ejurka.com>
Date: Tue Apr 1 07:19:38 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 f6df6e7..7c06856 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.9 2005/12/02 03:05:07 jurka Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/core/v2/ProtocolConnectionImpl.java,v 1.10 2006/12/01 08:53:45 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -62,7 +62,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 fcde241..ef8a680 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.10 2005/12/02 03:05:09 jurka Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/core/v3/ProtocolConnectionImpl.java,v 1.11 2006/12/01 08:53:45 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -65,7 +65,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 4e14024..71a865f 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.40.2.2 2007/12/01 09:17:49 jurka Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Connection.java,v 1.40.2.3 2008/02/19 06:12:41 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1009,6 +1009,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