Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Yg2VN-0000Za-Sk for pgsql-jdbc@arkaria.postgresql.org; Thu, 09 Apr 2015 02:47:46 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Yg2VN-0004zq-CP for pgsql-jdbc@arkaria.postgresql.org; Thu, 09 Apr 2015 02:47:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Yg2Er-00035K-88 for pgsql-jdbc@postgresql.org; Thu, 09 Apr 2015 02:30:41 +0000 Received: from mail.inomial.net ([202.62.159.215] helo=ix.inomial.com) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Yg2Ei-0004xN-7L for pgsql-jdbc@postgresql.org; Thu, 09 Apr 2015 02:30:38 +0000 Received: from pool1-148.office.inomial.com (pool1-148.office.inomial.com [192.168.1.148]) by ix.inomial.com (Postfix) with ESMTPSA id 675462C1ED5 for ; Thu, 9 Apr 2015 12:30:26 +1000 (AEST) From: Royce Ausburn Content-Type: multipart/alternative; boundary="Apple-Mail=_B33D7CA6-DC6A-44F6-AD6E-76AD78D190F0" Subject: Bug report: TCP deadlock between JDBC & Postgres Message-Id: Date: Thu, 9 Apr 2015 12:30:25 +1000 To: pgsql-jdbc@postgresql.org Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2070.6\)) X-Mailer: Apple Mail (2.2070.6) X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org --Apple-Mail=_B33D7CA6-DC6A-44F6-AD6E-76AD78D190F0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Hi all, We've managed to trip a deadlock between a JDBC client and postgres = similar to what's described in github issue #194 = (https://github.com/pgjdbc/pgjdbc/issues/194) and #195 = (https://github.com/pgjdbc/pgjdbc/issues/195). Here's a typical stack trace: "http-thread-pool-17580(4)" daemon prio=3D10 tid=3D0x00007f8224059000 = nid=3D0x66c8 runnable [0x00007f828670f000] java.lang.Thread.State: RUNNABLE at java.net.SocketOutputStream.socketWrite0(Native Method) at = java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113) at = java.net.SocketOutputStream.write(SocketOutputStream.java:159) at = java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82) at = java.io.BufferedOutputStream.write(BufferedOutputStream.java:126) - locked <0x00000006a40789a8> (a java.io.BufferedOutputStream) at java.io.FilterOutputStream.write(FilterOutputStream.java:97) at org.postgresql.core.PGStream.SendInteger4(PGStream.java:197) at = org.postgresql.core.v3.QueryExecutorImpl.sendCloseStatement(QueryExecutorI= mpl.java:1596) at = org.postgresql.core.v3.QueryExecutorImpl.processDeadParsedQueries(QueryExe= cutorImpl.java:1741) at = org.postgresql.core.v3.QueryExecutorImpl.sendQueryPreamble(QueryExecutorIm= pl.java:436) at = org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:25= 1) - locked <0x00000006a4078b68> (a = org.postgresql.core.v3.QueryExecutorImpl) at = org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement= .java:570) at = org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2= Statement.java:420) at = org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Stat= ement.java:305) An strace on the postgres server process end revealed the thread was = blocked sending data to the socket too. Netstat on both ends had bytes in the send-Q [royce@smile-test-db ~]$ netstat -an | grep 36563 tcp 57878 20016 10.20.18.204:5432 10.20.18.203:36563 = ESTABLISHED (sorry, I've lost the other end but it was nearly 64k of send-Q bytes, = believe me!) The issue emerged just after we've bumped the max JVM heap size = significantly and during a heavy running migration/data transformation = process with lots of jdbc queries. The issue appears to be in how processDeadParsedQueries() works - if = there're a lot of recently GC'd parsed statements then there'll be a lot = of statements to close which manages to fill the send buffer on our end = while the corresponding postgres process on the server end is busy = filling its send buffer with responses from the close statement = requests. =20 We believe that reducing the heap size will mean there're more frequent = GCs which will mean there'll be fewer statements to purge in any given = invocation of processDeadParsedQueries() so we can hopefully work around = this issue easily. --Royce --Apple-Mail=_B33D7CA6-DC6A-44F6-AD6E-76AD78D190F0 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii Hi all,

We've managed to trip a deadlock between a JDBC client and = postgres similar to what's described in github issue #194 (https://github.com/pgjdbc/pgjdbc/issues/194) and #195 (https://github.com/pgjdbc/pgjdbc/issues/195).

Here's a typical stack = trace:

"http-thread-pool-17580(4)" daemon prio=3D10 = tid=3D0x00007f8224059000 nid=3D0x66c8 runnable = [0x00007f828670f000]
   java.lang.Thread.State: RUNNABLE
        at = java.net.SocketOutputStream.socketWrite0(Native Method)
        at = java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
=
        at = java.net.SocketOutputStream.write(SocketOutputStream.java:159)
        at = java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at = java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
        - locked = <0x00000006a40789a8> (a java.io.BufferedOutputStream)
        at = java.io.FilterOutputStream.write(FilterOutputStream.java:97)
        at = org.postgresql.core.PGStream.SendInteger4(PGStream.java:197)
        at = org.postgresql.core.v3.QueryExecutorImpl.sendCloseStatement(QueryExecutorI= mpl.java:1596)
    =     at = org.postgresql.core.v3.QueryExecutorImpl.processDeadParsedQueries(QueryExe= cutorImpl.java:1741)
  =       at = org.postgresql.core.v3.QueryExecutorImpl.sendQueryPreamble(QueryExecutorIm= pl.java:436)
    =     at = org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:25= 1)
      =   - locked <0x00000006a4078b68> (a = org.postgresql.core.v3.QueryExecutorImpl)
        at = org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement= .java:570)
    =     at = org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2= Statement.java:420)
  =       at = org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Stat= ement.java:305)


An strace on the = postgres server process end revealed the thread was blocked sending data = to the socket too.

Netstat on = both ends had bytes in the send-Q

[royce@smile-test-db ~]$ netstat -an | grep 36563
tcp    57878  20016 10.20.18.204:5432   =     10.20.18.203:36563      ESTABLISHED
(sorry, I've lost the other end but it was nearly 64k of = send-Q bytes, believe me!)


The issue emerged just after we've bumped the max JVM heap = size significantly and during a heavy running migration/data = transformation process with lots of jdbc queries.

The issue appears to be in = how processDeadParsedQueries() works - if there're a lot of = recently GC'd parsed statements then there'll be a lot of statements to = close which manages to fill the send buffer on our end while the = corresponding postgres process on the server end is busy filling its = send buffer with responses from the close statement requests. =  

We believe that reducing the heap size will = mean there're more frequent GCs which will mean there'll be fewer = statements to purge in any given invocation of = processDeadParsedQueries() so we can hopefully work around this issue = easily.

--Royce



= --Apple-Mail=_B33D7CA6-DC6A-44F6-AD6E-76AD78D190F0--