Socket unexpectedly closed by a frontend while communicating with the backend

From: Mikhail Pryakhin <m(dot)pryahin(at)gmail(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Socket unexpectedly closed by a frontend while communicating with the backend
Date: 2014-01-21 21:00:39
Message-ID: CACgR--_QXh+Z0m8-un9vFci2pP0AL9QDcHs8BgYGMF4DvGbiww@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hello guys! I'm a little bit confused with the following case.

I've got a Postgressql server running on host A, and a java based client
running on host B. The client uses org.postgresql.Driver JDBC driver
(version 9.1-901.jdbc3).

sometimes while executing long running stored procedure I get exception
"java.net.SocketException: Socket closed". I'm using
org.apache.commons.dbcp.BasicDataSource for retrieving

connections. DBCP pool is configured with default options.

I got tcp dump in order to figure out on which side (client or server)
socket is being closed;

Here is what I've got:

1. Client B sends a test query message when tries to borrow connection
from dbcp pool ("Select 1")

2. Server A sends successful response back (Type: Command completion,
Ready for query)

3. Client B sends ACK message in response on server A response (see the
item 2).

4. Client B sends query message to the server A.

5. Server A sends ACK message in response on client Query message (see
the item 4).

6. Client B sends terminating message (Type : Termination) after some
time passed (from 3 to 10 or sometimes even more minutes).

7 Client B sends FIN ACK message to the server.

8. Server A sends back ACK on termination message.

9. Server A sends ACK on (FIN, ACK) message (item 7).

10. Server A sends back a response on the client query (from item 4) Type:
Row description Columns: 40.

11. Client B sends RST message (reset).

12. Server A continues sending response on the query Type: Data row
Length: 438 Columns 40 and so on.

13 Client B sends RST message (reset) again.

14. Server A continues sending response on the query Type: Data row
Length: 438 Columns 40 and so on.

15. Client B sends RST message (reset).

After that communication seems to be finished.

After the item 6, in my client logs I got Exception like the following:

Caused by: java.net.SocketException: Socket closed

at java.net.SocketInputStream.socketRead0(Native Method)

at java.net.SocketInputStream.read(SocketInputStream.java:152)

at java.net.SocketInputStream.read(SocketInputStream.java:122)

at
org.postgresql.core.VisibleBufferedInputStream.readMore(VisibleBufferedInputStream.java:145)

at
org.postgresql.core.VisibleBufferedInputStream.ensureBytes(VisibleBufferedInputStream.java:114)

at
org.postgresql.core.VisibleBufferedInputStream.read(VisibleBufferedInputStream.java:73)

at org.postgresql.core.PGStream.ReceiveChar(PGStream.java:274)

at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1661)

at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)

Could you please help me to figure out the reason of such a failure. (This
bug happens once per 10 successful cases.)

Thanks in advance!

Best regards, Mike Pryakhin.

Browse pgsql-bugs by date

  From Date Subject
Next Message Bruce Momjian 2014-01-21 21:37:26 Re: BUG #8869: ip4r93-1.05-3.rhel6 syntax error in ip4r.sql - LANGUAGE 'C' instead of LANGUAGE 'c'
Previous Message Tom Lane 2014-01-21 17:12:26 Re: BUG #8901: postgres_fdw double-qualifying schemas