【问题标题】:JDBC and Oracle 11g connection reset on ubuntuubuntu 上的 JDBC 和 Oracle 11g 连接重置
【发布时间】:2014-06-06 16:04:39
【问题描述】:

我在连接 JDBC 到 Oracle 11g 时遇到了这个奇怪的问题。这周一突然开始发生,我或团队都没有意识到任何设置更改。阅读 Stackoverflow 和 Oracle 论坛(请参阅底部的链接),我了解到在 linux 64 位机器上生成随机字节存在问题。它导致我尝试了几件事,不幸的是没有奏效。这是我所知道的所有信息的摘要。

奇怪的是我可以使用 sqlplus 通过终端连接,但不能使用 JDBC。

感谢您的任何想法或帮助,

阿米特

我的设置:

OS: Ubuntu 12.04
Java: Both 7 and 6_45 (Issue is the same)
JDBC: Downloaded from the Oracle official site (see further description down)
    Connection behind a Cisco VPN

JDBC 清单:

odbc7.jar:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Created-By: 20.12-b01 (Sun Microsystems Inc.)
Implementation-Vendor: Oracle Corporation
Implementation-Title: JDBC
Implementation-Version: 12.1.0.1.0
Repository-Id: JAVAVM_12.1.0.1.0_LINUX.X64_130403
Specification-Vendor: Sun Microsystems Inc.
Specification-Title: JDBC
Specification-Version: 4.0
Main-Class: oracle.jdbc.OracleDriver
sealed: true

Name: oracle/sql/converter/
Sealed: false

Name: oracle/sql/
Sealed: false

Name: oracle/sql/converter_xcharset/
Sealed: false

odbc6.jar:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Created-By: 20.12-b01 (Sun Microsystems Inc.)
Implementation-Vendor: Oracle Corporation
Implementation-Title: JDBC
Implementation-Version: 12.1.0.1.0
Repository-Id: JAVAVM_12.1.0.1.0_LINUX.X64_130403
Specification-Vendor: Sun Microsystems Inc.
Specification-Title: JDBC
Specification-Version: 4.0
Main-Class: oracle.jdbc.OracleDriver
sealed: true

Name: oracle/sql/converter/
Sealed: false

Name: oracle/sql/
Sealed: false

Name: oracle/sql/converter_xcharset/
Sealed: false

周五一切正常:

  • 我可以启动我的应用程序并与 Oracle DB 建立 Java 连接。
  • 从星期一开始我就遇到了这个问题
  • 我的旧电脑 (Ubuntu 12.04) 也是,我已经将近一周没有碰过这个问题,即使我让它处于工作状态。

使用 SQLPLUS 的终端连接工作正常:

amit@mymachine:/usr/lib/oracle$ sqlplus /@DB_HOST_IP:1521/DB_NAME

SQL*Plus:2014 年 4 月 22 日星期二 11:35:58 发布 12.1.0.1.0 生产版

版权所有 (c) 1982、2013、甲骨文。保留所有权利。

连接到: Oracle 数据库 11g 版本 11.2.0.3.0 - 64 位生产

SQL>

但与 JDBC 的连接失败:

DriverManager.getConnection(
                    "jdbc:oracle:thin:@//DB_HOST_IP:1521/DB_NAME", username,
                    password);

挂起约 20 秒后抛出:

ava.sql.SQLRecoverableException: IO Error: Connection reset
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:682)
    at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:711)
    at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:385)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:30)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:558)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:185)
    at OracleJDBC.main(OracleJDBC.java:32)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:168)
    at oracle.net.ns.Packet.receive(Packet.java:311)
    at oracle.net.ns.DataPacket.receive(DataPacket.java:105)
    at oracle.net.ns.NetInputStream.getNextPacket(NetInputStream.java:305)
    at oracle.net.ns.NetInputStream.read(NetInputStream.java:249)
    at oracle.net.ns.NetInputStream.read(NetInputStream.java:171)
    at oracle.net.ns.NetInputStream.read(NetInputStream.java:89)
    at oracle.jdbc.driver.T4CSocketInputStreamWrapper.readNextPacket(T4CSocketInputStreamWrapper.java:123)
    at oracle.jdbc.driver.T4CSocketInputStreamWrapper.read(T4CSocketInputStreamWrapper.java:79)
    at oracle.jdbc.driver.T4CMAREngineStream.unmarshalUB1(T4CMAREngineStream.java:426)
    at oracle.jdbc.driver.T4C8TTIdty.receive(T4C8TTIdty.java:688)
    at oracle.jdbc.driver.T4C8TTIdty.doRPC(T4C8TTIdty.java:595)
    at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1439)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:486)
    ... 12 more

来自服务器的日志:

Fatal NI connect error 12170.

  VERSION INFORMATION:
        TNS for Linux: Version 11.2.0.3.0 - Production
        Oracle Bequeath NT Protocol Adapter for Linux: Version
11.2.0.3.0 - Production
        TCP/IP NT Protocol Adapter for Linux: Version 11.2.0.3.0 - Production
  Time: 22-APR-2014 09:57:45
  Tracing not turned on.
  Tns error struct:
    ns main err code: 12535

TNS-12535: TNS:operation timed out
    ns secondary err code: 12606
    nt main err code: 0
    nt secondary err code: 0
    nt OS err code: 0
  Client address: (ADDRESS=(PROTOCOL=tcp)(HOST=<my.ip.address>)(PORT=42738))

来自两个服务器错误的 Oracle 文档:

ORA-12535: TNS:operation timed out
Cause: The requested operation could not be completed within the time out period.
Action: Look at the documentation on the secondary errors for possible remedy. See SQLNET.LOG to find secondary error if not provided explicitly. Turn on tracing to gather more information.

ORA-12606: TNS: Application timeout occurred
Cause: A network session did not reach an application-defined stage within the allowed time interval.
Action: This is an error which does not normally appear at the high level. The action to take is application specific, and is detailed in the higher level error description.

我尝试过的解决方案:

  1. 按照下面的 Stackoverflow 讨论中的建议添加以下系统属性 -Djava.security.egd=file:///dev/urandom
  2. 设置 rng-tools 以“帮助”操作系统的熵生成器。 (见链接)

  3. 以下代码运行没有问题,生成随机字节数组(不管参数-Djava.security.egd

int a = 10000; while (a-- > 0){ byte[] array = new byte[2048]; new SecureRandom().nextBytes(array); System.out.println(a); }

以上似乎都没有改变错误(超时)。

编辑:新尝试:

  1. 运行我的应用程序,我可以识别导致我出现实时问题的确切查询。这是在读取 1-2kb 大小的 CLOG 列时。

SQL&gt; select secure_params from session_token where id=11065073;

重启客户端,

不断更新此特定行中的此字段,如果该字段的大小为 429 个字符,我仍然可以读取该字段,但是当我将其增加到 587 个字符时,它又卡住了。

    SQL>  select length( secure_params) from session_token where id=11065073;

    LENGTH(SECURE_PARAMS)
    ---------------------
                      587

SQL&gt; select secure_params from session_token where id=11065073;

第 4 次尝试让我想到这里可能存在其他问题,因为应用程序能够创建初始连接并从数据库中获取一些短数据,但只有在结果集获得有点胖。

编辑结束

链接:

堆栈溢出:Oracle JDBC intermittent Connection Issue

Rng 熵生成器:http://www.howtoforge.com/helping-the-random-number-generator-to-gain-enough-entropy-with-rng-tools-debian-lenny

【问题讨论】:

    标签: oracle oracle11g ubuntu-12.04 ojdbc ora-12170


    【解决方案1】:

    ORA-12170 表示与数据库侦听器的 TCP 连接失败。

    如果这是一直发生的错误,请检查防火墙和网络 ACL。可能是中间人发生了变化?

    或者,它可能是影响 TCP 连接的其他一些因素,例如 IP 地址冲突。我自己最近也遇到了这个问题,并在 http://distracted-it.blogspot.co.nz/2014/04/ora-12170-tnsconnect-timeout-resolved.html 写了博客

    希望对你有帮助。

    【讨论】:

    • 嗨,Cameron,感谢这篇有趣的文章。我确实拍摄了wireshark,但你给了我更好的想法如何战略性地继续这样做。如果你有时间,请在那里查看我的编辑。也许您会有其他想法(参见解决方案尝试编号 4)
    • 我建议您可能遇到与数据包或 MTU 大小、路径 MTU 问题、巨型帧等有关的问题。如果通过路由器,则可能是由于不正确的防火墙对于 ICMP 您可能会发现 'ethtool --statistics eth0' 或 'netstat -s' 在帮助诊断这一点时很有用。您应该能够在不使用 sqlplus 的情况下对此进行测试。您可以尝试降低接口的 MTU (ifconfig eth0 mtu 1200) 而不是默认的 1500。有时需要 1460,尤其是在使用 IPv6 时。
    猜你喜欢
    • 2014-09-11
    • 2013-03-06
    • 2015-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-19
    • 1970-01-01
    相关资源
    最近更新 更多