pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedBug report: TCP deadlock between JDBC & Postgres
8+ messages / 4 participants
[nested] [flat]
* Bug report: TCP deadlock between JDBC & Postgres
@ 2015-04-09 02:30 Royce Ausburn <royce@inomial.com>
2015-04-09 15:01 ` Re: Bug report: TCP deadlock between JDBC & Postgres Dave Cramer <pg@fastcrypt.com>
2015-04-09 23:03 ` Re: Bug report: TCP deadlock between JDBC & Postgres Kris Jurka <books@ejurka.com>
2015-04-10 03:18 ` Re: Bug report: TCP deadlock between JDBC & Postgres Craig Ringer <craig@2ndquadrant.com>
0 siblings, 3 replies; 8+ messages in thread
From: Royce Ausburn @ 2015-04-09 02:30 UTC (permalink / raw)
To: pgsql-jdbc
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=10 tid=0x00007f8224059000 nid=0x66c8 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(QueryExecutorImpl.java:1596)
at org.postgresql.core.v3.QueryExecutorImpl.processDeadParsedQueries(QueryExecutorImpl.java:1741)
at org.postgresql.core.v3.QueryExecutorImpl.sendQueryPreamble(QueryExecutorImpl.java:436)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:251)
- locked <0x00000006a4078b68> (a org.postgresql.core.v3.QueryExecutorImpl)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:570)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:420)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.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
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Bug report: TCP deadlock between JDBC & Postgres
2015-04-09 02:30 Bug report: TCP deadlock between JDBC & Postgres Royce Ausburn <royce@inomial.com>
@ 2015-04-09 15:01 ` Dave Cramer <pg@fastcrypt.com>
2015-04-09 22:38 ` Re: Bug report: TCP deadlock between JDBC & Postgres Royce Ausburn <royce@inomial.com>
2015-04-10 03:18 ` Re: Bug report: TCP deadlock between JDBC & Postgres Craig Ringer <craig@2ndquadrant.com>
2 siblings, 2 replies; 8+ messages in thread
From: Dave Cramer @ 2015-04-09 15:01 UTC (permalink / raw)
To: Royce Ausburn <royce@inomial.com>; +Cc: pgsql-jdbc
Royce,
What version of the driver are you using ? It appears that Craig did commit
some code for the two issues you referenced.
Dave Cramer
dave.cramer(at)credativ(dot)ca
http://www.credativ.ca
On 8 April 2015 at 22:30, Royce Ausburn <royce@inomial.com> wrote:
> 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=10 tid=0x00007f8224059000
> nid=0x66c8 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(QueryExecutorImpl.java:1596)
> at
> org.postgresql.core.v3.QueryExecutorImpl.processDeadParsedQueries(QueryExecutorImpl.java:1741)
> at
> org.postgresql.core.v3.QueryExecutorImpl.sendQueryPreamble(QueryExecutorImpl.java:436)
> at
> org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:251)
> - locked <0x00000006a4078b68> (a
> org.postgresql.core.v3.QueryExecutorImpl)
> at
> org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:570)
> at
> org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:420)
> at
> org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.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
>
>
>
>
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Bug report: TCP deadlock between JDBC & Postgres
2015-04-09 02:30 Bug report: TCP deadlock between JDBC & Postgres Royce Ausburn <royce@inomial.com>
2015-04-09 15:01 ` Re: Bug report: TCP deadlock between JDBC & Postgres Dave Cramer <pg@fastcrypt.com>
@ 2015-04-09 22:38 ` Royce Ausburn <royce@inomial.com>
1 sibling, 0 replies; 8+ messages in thread
From: Royce Ausburn @ 2015-04-09 22:38 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; +Cc: pgsql-jdbc
Oops - sorry I missed that information.
We tried with 9.4 Build 1201 as well as an older version of the jdbc driver. The server is PostgreSQL 9.3.5.
Also, to follow up on this:
> 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.
This seems to have panned out for us. Our process would normally hang within a couple of hours with this deadlock. With a reduced heap it managed to survive a whole day now.
--Royce
> On 10 Apr 2015, at 1:01 am, Dave Cramer <pg@fastcrypt.com> wrote:
>
> Royce,
>
> What version of the driver are you using ? It appears that Craig did commit some code for the two issues you referenced.
>
> Dave Cramer
>
> dave.cramer(at)credativ(dot)ca
> http://www.credativ.ca <http://www.credativ.ca/;
>
> On 8 April 2015 at 22:30, Royce Ausburn <royce@inomial.com <mailto:royce@inomial.com>> wrote:
> 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 <https://github.com/pgjdbc/pgjdbc/issues/194;) and #195 (https://github.com/pgjdbc/pgjdbc/issues/195 <https://github.com/pgjdbc/pgjdbc/issues/195;).
>
> Here's a typical stack trace:
>
> "http-thread-pool-17580(4)" daemon prio=10 tid=0x00007f8224059000 nid=0x66c8 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(QueryExecutorImpl.java:1596)
> at org.postgresql.core.v3.QueryExecutorImpl.processDeadParsedQueries(QueryExecutorImpl.java:1741)
> at org.postgresql.core.v3.QueryExecutorImpl.sendQueryPreamble(QueryExecutorImpl.java:436)
> at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:251)
> - locked <0x00000006a4078b68> (a org.postgresql.core.v3.QueryExecutorImpl)
> at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:570)
> at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:420)
> at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.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 <http://10.20.18.204:5432/; 10.20.18.203 <http://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
>
>
>
>
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Bug report: TCP deadlock between JDBC & Postgres
2015-04-09 02:30 Bug report: TCP deadlock between JDBC & Postgres Royce Ausburn <royce@inomial.com>
2015-04-09 15:01 ` Re: Bug report: TCP deadlock between JDBC & Postgres Dave Cramer <pg@fastcrypt.com>
@ 2015-04-10 03:18 ` Craig Ringer <craig@2ndquadrant.com>
1 sibling, 0 replies; 8+ messages in thread
From: Craig Ringer @ 2015-04-10 03:18 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; +Cc: Royce Ausburn <royce@inomial.com>; pgsql-jdbc
On 9 April 2015 at 23:01, Dave Cramer <pg@fastcrypt.com> wrote:
> Royce,
>
> What version of the driver are you using ? It appears that Craig did
> commit some code for the two issues you referenced.
>
The work I did was related to batches that return generated keys. It won't
have any effect on cleanup of named queries.
--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Bug report: TCP deadlock between JDBC & Postgres
2015-04-09 02:30 Bug report: TCP deadlock between JDBC & Postgres Royce Ausburn <royce@inomial.com>
@ 2015-04-09 23:03 ` Kris Jurka <books@ejurka.com>
2015-04-10 02:59 ` Re: Bug report: TCP deadlock between JDBC & Postgres Royce Ausburn <royce@inomial.com>
2 siblings, 1 reply; 8+ messages in thread
From: Kris Jurka @ 2015-04-09 23:03 UTC (permalink / raw)
To: Royce Ausburn <royce@inomial.com>; +Cc: pgsql-jdbc
On Thu, 9 Apr 2015, Royce Ausburn wrote:
> 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.
>
Certainly the driver shouldn't deadlock in this situation and should only
send a limited number of close requests at once, but if your diagnosis is
correct that GC is triggering finalization of these resources, it seems
your application is partly at fault here. If these resources were closed
when complete instead of relying on GC, they would dissipate at a
reasonably rate and not cause this deadlock. Perhaps you need to add some
more close() calls to your code?
Kris Jurka
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Bug report: TCP deadlock between JDBC & Postgres
2015-04-09 02:30 Bug report: TCP deadlock between JDBC & Postgres Royce Ausburn <royce@inomial.com>
2015-04-09 23:03 ` Re: Bug report: TCP deadlock between JDBC & Postgres Kris Jurka <books@ejurka.com>
@ 2015-04-10 02:59 ` Royce Ausburn <royce@inomial.com>
0 siblings, 0 replies; 8+ messages in thread
From: Royce Ausburn @ 2015-04-10 02:59 UTC (permalink / raw)
To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc
> On 10 Apr 2015, at 9:03 am, Kris Jurka <books@ejurka.com> wrote:
>
>
>
> On Thu, 9 Apr 2015, Royce Ausburn wrote:
>
>> 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.
>>
>
> Certainly the driver shouldn't deadlock in this situation and should only
> send a limited number of close requests at once, but if your diagnosis is
> correct that GC is triggering finalization of these resources, it seems
> your application is partly at fault here. If these resources were closed
> when complete instead of relying on GC, they would dissipate at a
> reasonably rate and not cause this deadlock. Perhaps you need to add some
> more close() calls to your code?
>
> Kris Jurka
That's certainly a possibility!
I relayed this along to the engineer and he has already found a few places he isn't closing statements nor result sets! Thanks very much for pointing this out, I expect that this will resolve the issue better than carefully selecting a heap size and praying ;)
--Royce
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Bug report: TCP deadlock between JDBC & Postgres
2015-04-09 02:30 Bug report: TCP deadlock between JDBC & Postgres Royce Ausburn <royce@inomial.com>
@ 2015-04-10 03:18 ` Craig Ringer <craig@2ndquadrant.com>
2015-04-10 05:06 ` Re: Bug report: TCP deadlock between JDBC & Postgres Royce Ausburn <royce@inomial.com>
2 siblings, 1 reply; 8+ messages in thread
From: Craig Ringer @ 2015-04-10 03:18 UTC (permalink / raw)
To: Royce Ausburn <royce@inomial.com>; +Cc: pgsql-jdbc
On 9 April 2015 at 10:30, Royce Ausburn <royce@inomial.com> wrote:
> 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).
>
>
Please open a github issue for this.
--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Bug report: TCP deadlock between JDBC & Postgres
2015-04-09 02:30 Bug report: TCP deadlock between JDBC & Postgres Royce Ausburn <royce@inomial.com>
2015-04-10 03:18 ` Re: Bug report: TCP deadlock between JDBC & Postgres Craig Ringer <craig@2ndquadrant.com>
@ 2015-04-10 05:06 ` Royce Ausburn <royce@inomial.com>
0 siblings, 0 replies; 8+ messages in thread
From: Royce Ausburn @ 2015-04-10 05:06 UTC (permalink / raw)
To: Craig Ringer <craig@2ndquadrant.com>; +Cc: pgsql-jdbc
> On 10 Apr 2015, at 1:18 pm, Craig Ringer <craig@2ndquadrant.com> wrote:
>
>
>
> On 9 April 2015 at 10:30, Royce Ausburn <royce@inomial.com <mailto:royce@inomial.com>> wrote:
> 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 <https://github.com/pgjdbc/pgjdbc/issues/194;) and #195 (https://github.com/pgjdbc/pgjdbc/issues/195 <https://github.com/pgjdbc/pgjdbc/issues/195;).
>
>
> Please open a github issue for this.
>
Done.
https://github.com/pgjdbc/pgjdbc/issues/279 <https://github.com/pgjdbc/pgjdbc/issues/279;
--Royce=
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2015-04-10 05:06 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-04-09 02:30 Bug report: TCP deadlock between JDBC & Postgres Royce Ausburn <royce@inomial.com>
2015-04-09 15:01 ` Dave Cramer <pg@fastcrypt.com>
2015-04-09 22:38 ` Royce Ausburn <royce@inomial.com>
2015-04-10 03:18 ` Craig Ringer <craig@2ndquadrant.com>
2015-04-09 23:03 ` Kris Jurka <books@ejurka.com>
2015-04-10 02:59 ` Royce Ausburn <royce@inomial.com>
2015-04-10 03:18 ` Craig Ringer <craig@2ndquadrant.com>
2015-04-10 05:06 ` Royce Ausburn <royce@inomial.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox