Re: JDBC client hangs on socketRead()

From: Dave Cramer <pg(at)fastcrypt(dot)com>
To: Michał Niklas <michal(dot)niklas(at)heuthes(dot)pl>
Cc: List <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: JDBC client hangs on socketRead()
Date: 2016-05-24 12:47:01
Message-ID: CADK3HHKuVpV02h=3-teUQGCjPufFesr+5MbTYMmxserMVXgQ=w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

My guess is that somehow two threads are using the same connection. Is that
probable?

Dave Cramer

davec(at)postgresintl(dot)com
www.postgresintl.com

On 24 May 2016 at 08:33, Michał Niklas <michal(dot)niklas(at)heuthes(dot)pl> wrote:

> 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
>
>
>
>

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Dave Cramer 2016-05-24 12:49:13 Re: JDBC failing due to networking issues
Previous Message Michał Niklas 2016-05-24 12:33:43 JDBC client hangs on socketRead()