pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michał Niklas <michal.niklas@heuthes.pl>
To: List <pgsql-jdbc@postgresql.org>
Subject: JDBC client hangs on socketRead()
Date: Tue, 24 May 2016 14:33:43 +0200
Message-ID: <c4695c6f-e9e1-e089-3499-b1a5e7bf112c@heuthes.pl> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>

I have multithread Java service using JDBC connections from pool and
sometimes it hangs some threads at socketRead() while PostgreSQL shows
that all connections are in idle state.

My internal logging shows that the last statement I called in those
threads was:

	ResultSet rs = stmt.executeQuery();

From my client jstack output looks like:

"/client1_160524084431" #65702 daemon prio=5 os_prio=0
tid=0x00007fc2fc016800 nid=0x10c9 runnable [0x00007fc297ffd000]
   java.lang.Thread.State: RUNNABLE
	at java.net.SocketInputStream.socketRead0(Native Method)
	at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
	at java.net.SocketInputStream.read(SocketInputStream.java:170)
	at java.net.SocketInputStream.read(SocketInputStream.java:141)
	at
org.postgresql.core.VisibleBufferedInputStream.readMore(VisibleBufferedInputStream.java:143)
	at
org.postgresql.core.VisibleBufferedInputStream.ensureBytes(VisibleBufferedInputStream.java:112)
	at
org.postgresql.core.VisibleBufferedInputStream.read(VisibleBufferedInputStream.java:70)
	at org.postgresql.core.PGStream.ReceiveChar(PGStream.java:283)
	at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1799)
	at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:200)
	- locked <0x00000005dea42868> (a org.postgresql.core.v3.QueryExecutorImpl)
	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:424)
	at
org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:161)
	at
org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:114)
	...

"/client2_160524084407" #65374 daemon prio=5 os_prio=0
tid=0x00007fc2fc0e8800 nid=0xf81 runnable [0x00007fc2adbfc000]
   java.lang.Thread.State: RUNNABLE
	at java.net.SocketInputStream.socketRead0(Native Method)
	at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
	at java.net.SocketInputStream.read(SocketInputStream.java:170)
	at java.net.SocketInputStream.read(SocketInputStream.java:141)
	at
org.postgresql.core.VisibleBufferedInputStream.readMore(VisibleBufferedInputStream.java:143)
	at
org.postgresql.core.VisibleBufferedInputStream.ensureBytes(VisibleBufferedInputStream.java:112)
	at
org.postgresql.core.VisibleBufferedInputStream.read(VisibleBufferedInputStream.java:70)
	at org.postgresql.core.PGStream.ReceiveChar(PGStream.java:283)
	at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1799)
	at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:200)
	- locked <0x00000005df264838> (a org.postgresql.core.v3.QueryExecutorImpl)
	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:424)
	at
org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:161)
	at
org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:114)
	...

(more similar threads, all trying to socketRead())
...

At server side those connections show idle state:

polkitd    736  0.0  0.0 8512128 30464 ?       Ss   07:59   0:00
postgres: postgres client1 192.168.1.124(47685) idle
polkitd    857  0.0  0.0 8509548 20824 ?       Ss   08:02   0:00
postgres: postgres client2 192.168.1.124(47809) idle
...
(more similar connections)

My environment:

Client:
OS: Linux
JVM: 1.8.0_92 (Oracle Corporation)
JDBC: postgresql-9.4.1208.jar, Java JDBC 4.2 (JRE 8+) driver for
PostgreSQL database

Server:
Version: PostgreSQL 9.5.3 on x86_64-pc-linux-gnu, compiled by gcc
(Debian 4.9.2-10) 4.9.2, 64-bit
OS: Linux

Both service and database server runs on separate docker environments.


My question is:
Why I observe such hanging threads?

-- 
Regards,
Michał Niklas

Attachments:

  signature.asc (application/pgp-signature, 472B) download

view thread (3+ messages)  latest in thread

Message-ID: <c4695c6f-e9e1-e089-3499-b1a5e7bf112c@heuthes.pl>
Permalink:  ../c4695c6f-e9e1-e089-3499-b1a5e7bf112c@heuthes.pl/
Also on:    postgresql.org/message-id/c4695c6f-e9e1-e089-3499-b1a5e7bf112c@heuthes.pl

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: michal.niklas@heuthes.pl
  Subject: Re: JDBC client hangs on socketRead()
  In-Reply-To: <c4695c6f-e9e1-e089-3499-b1a5e7bf112c@heuthes.pl>
  References: <c4695c6f-e9e1-e089-3499-b1a5e7bf112c@heuthes.pl>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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