13

I'm having a problem when connecting to an Oracle database, it takes a long time (about ~5 minutes) and it sends the below shown exception. Most of the time, after the first error, the next connections for the same process work correctly.

It is a RHEL 6 machine, with two different network interfaces and ip addresses.

NOTE: I am not using an url like: "jdbc:oracle:thin:@xxxx:yyy, it is actually: "jdbc:oracle:thin:@xxxx:yyyy:zzz. The SID is not missing, sorry for that :(

This is roughly what I've isolated:

bin/java -classpath ojdbc6_g.jar -Djavax.net.debug=all -Djava.util.logging.config.file=logging.properties

Class.forName ("oracle.jdbc.OracleDriver")
DriverManager.getConnection("jdbc:oracle:thin:@xxxx:yyyy", "aaaa", "bbbb")

Error StackTrace:

java.sql.SQLRecoverableException: IO Error: Connection reset
        at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:533)
        at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:557)
        at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:233)
        at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:29)
        at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:556)
        at java.sql.DriverManager.getConnection(DriverManager.java:579)
        at java.sql.DriverManager.getConnection(DriverManager.java:221)
        at test.jdbc.Main(Test.java:120)
Caused by: java.net.SocketException: Connection reset
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
        at oracle.net.ns.DataPacket.send(DataPacket.java:248)
        at oracle.net.ns.NetOutputStream.flush(NetOutputStream.java:227)
        at oracle.net.ns.NetInputStream.getNextPacket(NetInputStream.java:309)
        at oracle.net.ns.NetInputStream.read(NetInputStream.java:257)
        at oracle.net.ns.NetInputStream.read(NetInputStream.java:182)
        at oracle.net.ns.NetInputStream.read(NetInputStream.java:99)
        at oracle.jdbc.driver.T4CSocketInputStreamWrapper.readNextPacket(T4CSocketInputStreamWrapper.java:121)
        at oracle.jdbc.driver.T4CSocketInputStreamWrapper.read(T4CSocketInputStreamWrapper.java:77)
        at oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:1173)
        at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:309)
        at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:200)
        at oracle.jdbc.driver.T4CTTIoauthenticate.doOSESSKEY(T4CTTIoauthenticate.java:404)
        at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:430)
        ... 35 more

There's a very verbose log of what happens over here: http://pastebin.com/MMFKU26z The line that says GET STUCK HERE represents the 5 minute waiting time

iamedu
  • 295
  • 4
  • 15

2 Answers2

27

You are probably running into an issue with the Oracle JDBC driver which uses a blocking random number generator by default on Linux. Try running Java with the following argument:

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

Alternatively you could start up a daemon to feed the random number generator. The Linux "rngd" daemon is an example.

Sources:

Community
  • 1
  • 1
Ryan
  • 7,499
  • 9
  • 52
  • 61
  • I wish I could give this more votes. This fixed _everything_ with my slow connections to oracle on my monitoring system...running on Ubuntu 14.04.3 LTS. – David Webb Feb 16 '16 at 01:52
1

Looking at your connection string, it seems that Oracle service name or SID is missing. The connection string should look like "jdbc:oracle:thin:@xxxx:yyyy/zzz", where zzz is the SID. You may also want to have a look at the answer to this question.

Community
  • 1
  • 1
maksim_khokhlov
  • 794
  • 5
  • 8
  • Please, read question carefully: *Most of the time, after the first error, the next connections for the same process work correctly.* – Andremoniy Jan 18 '13 at 14:20
  • 1
    @Andremoniy The question part you cited can be a result of TNS listener behavior. So from the perspective of a TNS listener, it can look like this: some client establishes a connection, but doesn't say what particular service it wants to use. The listener waits for some time, and finally resets the connection. Anyway, the format of connection string in the example code is incorrect - that's why I addressed it. – maksim_khokhlov Jan 18 '13 at 14:44
  • Sorry!!! My bad, when I hid the parameters i forgot the SID, but it is there the actual form is: "jdbc:oracle:thin:@xxxx:yyyy:zzz" – iamedu Jan 18 '13 at 15:08