【发布时间】:2014-01-22 11:48:53
【问题描述】:
我对以下情况有点困惑。
我在主机 A 上运行了一个 Postgres 服务器,在主机 B 上运行了一个基于 java 的客户端。客户端使用 org.postgresql.Driver JDBC 驱动程序(版本 9.1-901.jdbc3)。
有时在执行长时间运行的存储过程时出现异常“java.net.SocketException: Socket closed”。我正在使用org.apache.commons.dbcp.BasicDataSource 进行检索
连接。
DBCP 池配置有默认选项。
我得到了 tcp 转储,以便确定正在关闭哪一侧(客户端或服务器)的套接字;
这是我得到的:
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).
在那之后,通信似乎结束了。
在第 6 项之后,在我的客户端日志中出现如下异常:
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)
请您帮我找出这种失败的原因。 (此错误每 10 个成功案例发生一次。)
【问题讨论】:
-
PostgreSQL 错误日志中会出现什么(如果有)?考虑使用
log_min_messages = debug3重新启动 PostgreSQL,以获得详细、详细(和巨大)的日志。你需要一个合适的log_line_prefix,这样你就可以知道哪个会话是哪个会话。还有,PostgreSQL 版本? (SELECT version())。最后,客户端和服务器之间的网络是什么样的?多少跳?互联网,还是只有局域网?涉及WiFi?任何 NAT、防火墙、代理、连接跟踪路由器?
标签: postgresql jdbc apache-commons-dbcp