94

I'm running Oracle 11GR2 on an Amazon RDS instance. occasionally I get an IO Error: Got minus one from a read call when making a call to DriverManager.getConnection(getUrl()) and I'm not sure why. Other applications work correctly.

To further confuse things, the error will correct itself on occasion (following next iteration of the program).

How should I approach a "Got minus one from a read call" error?

Full stack trace:

java.sql.SQLRecoverableException: IO Error: Got minus one from a read call
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:489)
    at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:553)
    at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:254)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:528)
    at java.sql.DriverManager.getConnection(DriverManager.java:579)
    at java.sql.DriverManager.getConnection(DriverManager.java:243)
    at com.cwd.facile.db.Database.<init>(Database.java:44)
    at com.cwd.facile.ns.NetSuiteRequestBased.<init>(NetSuiteRequestBased.java:29)
    at com.cwd.facile.ns.CommonOperations.isInventoryItem(CommonOperations.java:205)
    at com.cwd.facile.ns.CommonOperations.findItemIdByName(CommonOperations.java:188)
    at com.cwd.facile.ns.CommonOperations.createSalesOrder(CommonOperations.java:970)
    at com.cwd.facile.Main.main(Main.java:47)
Caused by: oracle.net.ns.NetException: Got minus one from a read call
    at oracle.net.ns.Packet.receive(Packet.java:311)
    at oracle.net.ns.NSProtocol.connect(NSProtocol.java:300)
    at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1140)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:340)
    ... 12 more

Database.java line 44: setConn(DriverManager.getConnection(getUrl()));

Other info:

  • I thought it was a bad JDBC url, but it does work, sometimes for days on end before failing.
  • Amazon RDS is a managed instance and configuration changes may not be possible
  • I am using ojdbc6.jar for connectivity
Robert H
  • 11,520
  • 18
  • 68
  • 110
  • Consider this question also: https://stackoverflow.com/questions/31704622 Possibly the OracleDriver you are using is deprecated. – Raul Luna Aug 06 '19 at 12:59

7 Answers7

124

The immediate cause of the problem is that the JDBC driver has attempted to read from a network Socket that has been closed by "the other end".

This could be due to a few things:

  • If the remote server has been configured (e.g. in the "SQLNET.ora" file) to not accept connections from your IP.

  • If the JDBC url is incorrect, you could be attempting to connect to something that isn't a database.

  • If there are too many open connections to the database service, it could refuse new connections.

Given the symptoms, I think the "too many connections" scenario is the most likely. That suggests that your application is leaking connections; i.e. creating connections and then failing to (always) close them.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • 3
    I had this error while running Oracle DB locally (in docker). Turned out I have to use real IP of host machine to connect instead of `localhost` or `127.0.0.1`. How convenient... – expert Jun 28 '22 at 10:17
  • 2
    Yea ... within a container `localhost` most likely refers to something (or nothing!) in the container itself; see https://stackoverflow.com/questions/24319662. Note that "host.docker.internal" is a possible alternative to using the host's real IP. It will depend on what IP address(es) the Oracle DB on the host is actually configured to listen on. – Stephen C Jan 05 '23 at 07:40
21

We faced the same issue and fixed it. Below is the reason and solution.

Problem

When the connection pool mechanism is used, the application server (in our case, it is JBOSS) creates connections according to the min-connection parameter. If you have 10 applications running, and each has a min-connection of 10, then a total of 100 sessions will be created in the database. Also, in every database, there is a max-session parameter, if your total number of connections crosses that border, then you will get Got minus one from a read call.

FYI: Use the query below to see your total number of sessions:

SELECT username, count(username) FROM v$session 
WHERE username IS NOT NULL group by username

Solution: With the help of our DBA, we increased that max-session parameter, so that all our application min-connection can accommodate.

Wild Pottok
  • 318
  • 3
  • 8
Arnab Sarkar
  • 221
  • 2
  • 2
  • If you exceed MAXPROCESS or MAXSESSION you do get however ORA- errors specific to that situation, the connection is not simply closed. – eckes Mar 12 '16 at 09:54
17

I got this error message from using an oracle database in a docker despite the fact i had publish port to host option "-p 1521:1521". I was using jdbc url that was using ip address 127.0.0.1, i changed it to the host machine real ip address and everything worked then.

  • me paso lo mismo – Guillermo Solana Jul 26 '21 at 20:33
  • 1
    It worked for me too. Only put the internal server address IP. no is necessary to put a public IP. – Felipe Cabral Nov 13 '21 at 23:00
  • Worked for me too. I run Oracle DB 19 in Docker and when I tried to connect using a JDBC driver and localhost address, I got the error. When I changed localhost to the direct IP address, reported by Docker inspect as the IPAddress, 172.17.0.2 in my machine, all started to work. – OndroMih Mar 07 '22 at 21:41
  • wow... why Oracle couldn't explain that in theirs documentation to start a container instace of Oracle DB? They just say "use localhost:1521". Seems like they never tested their own container... Thanks Dude. – Vash79 Jul 22 '22 at 15:13
4

I had a similar issue when running Oracle 21c XE image on Docker locally when I was trying to connect to it by localhost or 127.0.0.1.

The fix was to log in into the container and modify sqlnet.ora in the following way:

echo "DISABLE_OOB=ON" >> /opt/oracle/oradata/dbconfig/XE/sqlnet.ora

and restart the container.

malloc4k
  • 1,742
  • 3
  • 22
  • 22
  • For me `echo "DISABLE_OOB=ON" >> "$ORACLE_HOME/network/admin/sqlnet.ora"` option worked on container-registry.oracle.com/database/express:18.4.0-xe, but not on container-registry.oracle.com/database/express:21.3.0-xe docker image. No idea why. – anre Aug 10 '22 at 14:50
2

I would like to augment to Stephen C's answer, my case was on the first dot. So since we have DHCP to allocate IP addresses in the company, DHCP changed my machine's address without of course asking neither me nor Oracle. So out of the blue oracle refused to do anything and gave the minus one dreaded exception. So if you want to workaround this once and for ever, and since TCP.INVITED_NODES of SQLNET.ora file does not accept wildcards as stated here, you can add you machine's hostname instead of the IP address.

Stelios Adamantidis
  • 1,866
  • 21
  • 36
  • This is why we have static IPs for servers. Alternatively, if you want to use DHCP, you can assign the MAC address a specific IP via DHCP reservations. – Sun Aug 31 '16 at 15:33
  • @Sun My PC was _the_ server. – Stelios Adamantidis Aug 31 '16 at 18:26
  • 1
    Yeah, if you don't have control over IP provisioning... not much you can do but hope hostname will keep up with the IP address changes. – Sun Aug 31 '16 at 18:27
0

in my case, I got the same exception because the user that I configured in the app did not existed in the DB, creating the user and granting needed permissions solved the problem.

Rahul Gupta
  • 1,079
  • 2
  • 15
  • 27
-3

Cause

oracle binary permission issue ($ORACLE_HOME/bin/oracle)

[tst19c@exa033dbadm01 bin]$ $ORACLE_HOME/bin

[tst19c@exa033dbadm01 bin]$ ls -ltr oracle

-rwxr-s--x 1 tst19c asmadmin 446528768 May 3 14:28 oracle

Action Taken

[tst19c@exa033dbadm01 bin]$ chmod 6751 oracle

[tst19c@exa033dbadm01 bin]$ ls -ltr oracle

Now

-rwsr-s--x 1 tst19c asmadmin 446528768 May 3 14:28 oracle

[tst19c@exa033dbadm01 bin]$

Atul Patel
  • 543
  • 4
  • 11