Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b5BXW-0005Nb-Gg for pgsql-jdbc@arkaria.postgresql.org; Tue, 24 May 2016 12:34:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1b5BXW-0001kY-0V for pgsql-jdbc@arkaria.postgresql.org; Tue, 24 May 2016 12:34:26 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1b5BX0-0000di-Sy for pgsql-jdbc@postgresql.org; Tue, 24 May 2016 12:33:55 +0000 Received: from mail.heuthes.pl ([213.76.141.132] helo=poczta.heuthes.pl) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1b5BWx-0007wl-Fm for pgsql-jdbc@postgresql.org; Tue, 24 May 2016 12:33:53 +0000 To: List From: =?UTF-8?Q?Micha=c5=82_Niklas?= Subject: JDBC client hangs on socketRead() Message-ID: Date: Tue, 24 May 2016 14:33:43 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="g558mEol61NfnmM7rdpqO0MH0vxmxA64a" X-Pg-Spam-Score: -3.3 (---) 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 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --g558mEol61NfnmM7rdpqO0MH0vxmxA64a From: =?UTF-8?Q?Micha=c5=82_Niklas?= To: List Message-ID: Subject: JDBC client hangs on socketRead() Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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 =3D stmt.executeQuery(); =46rom my client jstack output looks like: "/client1_160524084431" #65702 daemon prio=3D5 os_prio=3D0 tid=3D0x00007fc2fc016800 nid=3D0x10c9 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(VisibleBufferedInpu= tStream.java:143) at org.postgresql.core.VisibleBufferedInputStream.ensureBytes(VisibleBufferedI= nputStream.java:112) at org.postgresql.core.VisibleBufferedInputStream.read(VisibleBufferedInputStr= eam.java:70) at org.postgresql.core.PGStream.ReceiveChar(PGStream.java:283) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.j= ava: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(PgPreparedStatemen= t.java:161) at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.ja= va:114) ... "/client2_160524084407" #65374 daemon prio=3D5 os_prio=3D0 tid=3D0x00007fc2fc0e8800 nid=3D0xf81 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(VisibleBufferedInpu= tStream.java:143) at org.postgresql.core.VisibleBufferedInputStream.ensureBytes(VisibleBufferedI= nputStream.java:112) at org.postgresql.core.VisibleBufferedInputStream.read(VisibleBufferedInputStr= eam.java:70) at org.postgresql.core.PGStream.ReceiveChar(PGStream.java:283) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.j= ava: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(PgPreparedStatemen= t.java:161) at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.ja= va: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? --=20 Regards, Micha=C5=82 Niklas --g558mEol61NfnmM7rdpqO0MH0vxmxA64a Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJXREooAAoJEBZyBHPmeGAedmAIAKSHo0e9Tqz2vJhTJUytOlwP ntda0lO84noMFjg/Lodt0+v+Hbv5u65U3WccPzOarTEEJ2l9k+6FqKOl9+8lhjfq a7+NYoDAxYCw71iqj0FBreSzSovaO1t++fnCFrklhkmutVbpWnv6oQ565JKtXqmk Xz9a9/lS11zQW3H6LzGU7Zxx2rNsEiEfBL3TkUZqm+Sh06cVude9gzeuMpEI6QGQ TzvgtG9mlMsLyDqYVHfDnVzku8WZvM4wnhWF/0gcZVC9J7b4QxoWXA4xtJ49MyKL ZcdWlsVitIr01LS33DN7Wt+q+XPtM9aqk42go2/ikmoUCpBVROPFvFBSqMrFMb4= =ugZo -----END PGP SIGNATURE----- --g558mEol61NfnmM7rdpqO0MH0vxmxA64a--