仅在调试时:java.io.IOException:远程主机强制关闭现有连接

时间:2018-03-27 12:01:13

标签: oracle debugging intellij-idea jdbc

我有一个访问Oracle 12数据库的Java应用程序。当我在调试器外部运行时,它运行正常。如果我尝试使用IntelliJ的v2016.1.4调试器进行调试,我得到一个java.sql.SQLRecoverableException,其中包含以下堆栈跟踪:

java.sql.SQLRecoverableException: IO Error: An existing connection was forcibly closed by the remote host, Authentication lapse 0 ms.
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:794) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
    at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:688) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:39) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:691) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
    at oracle.jdbc.pool.OracleDataSource.getPhysicalConnection(OracleDataSource.java:384) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
    at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:273) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
    at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:198) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
    at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:176) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
    at ...setDbConnection(OracleJmsQueue.java:537) [classes/:?]
    ...
Caused by: java.io.IOException: An existing connection was forcibly closed by the remote host, Authentication lapse 0 ms.
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:790) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
    ... 12 more
Caused by: java.io.IOException: An existing connection was forcibly closed by the remote host
    at sun.nio.ch.SocketDispatcher.write0(Native Method) ~[?:1.8.0_131]
    at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:51) ~[?:1.8.0_131]
    at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93) ~[?:1.8.0_131]
    at sun.nio.ch.IOUtil.write(IOUtil.java:65) ~[?:1.8.0_131]
    at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:471) ~[?:1.8.0_131]
    at oracle.net.nt.TimeoutSocketChannel.write(TimeoutSocketChannel.java:215) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
    at oracle.net.ns.NIOPacket.writeToSocketChannel(NIOPacket.java:211) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
    at oracle.net.ns.NIONSDataChannel.writeDataToSocketChannel(NIONSDataChannel.java:181) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
    at oracle.net.ns.NIONSDataChannel.writeDataToSocketChannel(NIONSDataChannel.java:132) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
    at oracle.jdbc.driver.T4CMAREngineNIO.prepareForReading(T4CMAREngineNIO.java:96) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
    at oracle.jdbc.driver.T4CMAREngineNIO.unmarshalUB1(T4CMAREngineNIO.java:534) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
    at oracle.jdbc.driver.T4C8TTIdty.receive(T4C8TTIdty.java:728) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
    at oracle.jdbc.driver.T4C8TTIdty.doRPC(T4C8TTIdty.java:639) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
    at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1544) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:518) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
    ... 12 more

有趣的是,这只会在调试时发生。我可以在调试器外启动Java进程,使用JPDA启用远程调试,一切运行正常。如果我然后附加远程IntelliJ调试器,则会出现问题。如果我然后分离调试器,Java进程将再次正常运行。以下是发生异常的代码:

protected void setDbConnection(DataSource dataSource)
        throws InterruptedException {
    boolean connected = false;
    while (!connected) {
        try {
            dbConnection = dataSource.getConnection();
            dbConnection.setAutoCommit(false);
            connected = true;
        }
        catch (SQLException e) {
            int retryTime = 5000; // 5 seconds
            final String msg =
                    String.format("Unable to connect to %s.  Retrying in %s ms",
                                  dataSource, retryTime);
            logger.error(msg, e);
            Thread.sleep(retryTime);
        }
    }
    logConnectionDebugInfo();
}

以下是调试器提供的调试信息。我注意到SQLState的“08006”,但未能找到有关它的有用信息。我欢迎任何关于这个问题的想法。大多数情况下,我想解决它,但我也想听听它可能导致它的调试问题。这可能是一些线程问题吗?

enter image description here

更新3/28/2018:我可以使用Eclipse的Neon.3 Release(4.6.3)调试器进行调试,而不会出现此问题。

1 个答案:

答案 0 :(得分:0)

我在 eclipse 2020-12 中遇到了完全相同的问题。我删除了所有断点,它工作正常。似乎某些断点正在减慢它的速度,然后一旦超时,远程主机就会强行关闭现有连接。