SQLRecoverableException: I / O exception: connection reset

Last night I left my office with a Java program written by me. He must insert many records into our company database (Oracle) using the JDBC connection. This morning, when I returned to work, I saw this error (caught by an attempt):

java.sql.SQLRecoverableException: I/O Exception: Connection reset 

The program wrote almost all the notes before solving this problem, but what if it happens earlier (a few minutes after I leave the office in the evening)? I can’t understand what happened, I contacted the database administrator and said that there are no special problems in the database.

Any idea on what happened and what can I do to avoid this?

+13
source share
6 answers

It just means that something in the backend (DBMS) decided to stop working due to inaccessibility of resources, etc. This has nothing to do with your code or the number of inserts. You can learn more about similar issues here:

This may not answer your question, but you will understand why this may happen. You can discuss with your database administrator and see if there is anything specific in your case.

+12
source

The error occurs in some RedHat distributions. The only thing you need to do is run the application with the java.security.egd = file: /// dev / urandom parameter:

 java -Djava.security.egd=file:///dev/urandom [your command] 
+23
source

I want to give an additional answer about the nacho-soriano solution ...

I recently tried to solve a problem when a Java-written application (actually this is a Talend ELT job) wants to connect to an Oracle database (11g or more), and then a crash happens by accident. Operating system RedHat Enterprise and CentOS. The task runs very quickly in time (no more than half a minute) and runs very often (approximately one run every 5 minutes).

Sometimes, at night, as working hours, during intensive use of the database in the form of lazy use, in a word, randomly, the connection with this message fails:

 Exception in component tOracleConnection_1 java.sql.SQLRecoverableException: Io exception: Connection reset at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:101) at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:112) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:173) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:229) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:458) at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:411) at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:490) at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:202) at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:33) at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:465) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:208) and StackTrace follow ... 

Explanation of the problem:

As detailed here

An Oracle connection requires random numbers to provide a good level of security. Linux random number generator generates some numbers based on keyboard and mouse activity (among others) and pushes them on the stack. You will give me, on the server, there is not a lot of such activity. So it may happen that programs use more random numbers than a generator can produce.

When the pool is empty, reading from / dev / random will be blocked until additional environmental noise is collected. And the Oracle connection timed out (60 seconds by default).

Solution 1 - Specially for one application

The solution is to add two parameters specified by the JVM at startup:

 -Djava.security.egd=file:/dev/./urandom -Dsecurerandom.source=file:/dev/./urandom 

Note: "/./" is important, do not drop it!

Thus, the launch command line can be:

 java -Djava.security.egd=file:/dev/./urandom -Dsecurerandom.source=file:/dev/./urandom -cp <classpath directives> appMainClass <app options and parameters> 

One of the drawbacks of this solution is that the generated numbers are slightly less secure due to the influence of randomness. If you are not working in the military or secret industry, this decision may be yours.

Solution 2 - Generic Java JVM Solution

As explained here

Both directives in solution 1 can be placed in the Java security settings file.

Take a look at $JAVA_HOME/jre/lib/security/java.security

Change line

 securerandom.source=file:/dev/random 

in

 securerandom.source=file:/dev/urandom 

The change takes effect immediately for newly launched applications.

As for solution No. 1, one of the drawbacks of this solution is that the generated numbers are slightly less secure due to the influence of randomness. This time it's the global influence of the JVM. As for Decision No. 1, if you are not working in the military or secret industry, this decision may be yours.

Ideally, we should use "file: /dev/./urandom" after Java 5, since the previous path will again point to / dev / random.

Reported error: https://bugs.openjdk.java.net/browse/JDK-6202721

Solution 3 - Hardware Solution

Disclaimer: I am not affiliated with any of the suppliers of equipment or product ...

If you need to achieve a high level of randomness, you can replace the software of your Linux random number generator with hardware.

Some information is available here .

respectfully

Thomas

+11
source

Decision
Change the setting for your application so that you specify this parameter [ -Djava.security.egd = file: /dev/../dev/urandom ] next to the java command:

Java -Djava.security.egd = file: /dev/../dev/urandom [your command]

Link: - https://community.oracle.com/thread/943911

+5
source

We experienced these errors intermittently after upgrading from 11g to 12c, and our java was at 1.6.

The fix for us was updating java and jdbc from 6 to 7

 export JAVA_HOME='/usr/java1.7' export CLASSPATH=/u01/app/oracle/product/12.1.0/dbhome_1/jdbc/libojdbc7.jar:$CLASSPATH 

A few days later, the connection is still interrupted.

We have finished removing all java 7 above. Java 6 is fine. The problem was fixed by adding this to our bash_profile user.

Our groovy scripts that experienced the error used / dev / random on our VM batch server. The following is forcing java and groovy to use / dev / urandom.

export JAVA_OPTS = "$ JAVA_OPTS -Djava.security.egd = file: /// dev / urandom"

+4
source

Your exception says everything "Connection reset". The connection between your java process and the db server was lost, which could happen for almost any reason (for example, network problems). SQLRecoverableException simply means that it is being recoverable, but the main reason is the reset connection.

+2
source

Source: https://habr.com/ru/post/888903/


All Articles