What are the reasons for getting a Socket read timed out Exception in Java?
I’m gettting:
### Cause: java.sql.SQLRecoverableException: IO Error: Socket read timed out
; SQL []; IO Error: Socket read timed out; nested exception is java.sql.SQLRecoverableException: IO Error: Socket read timed out
asked Oct 3, 2016 at 12:07
Depending on your environment, there can be many different reasons: it could be a simple network outage between your machine and the database server. But it could also be that there is a congestion on a lower level; and one layer just sits there; all connection threads taken; waiting for some other side to move … that won’t move any more.
In that sense, the unspecific answer to your unspecific question is: identify the different components that exist in your system and that need to communicate with each other in order to deliver the functionality that they are supposed to deliver. When you have that «map»; you start checking each location on that map by its own.
And hint: if you don’t have such a (mental) map yet; well, welcome to the world of professional IT. When you are responsible for a complex system; you simply have to understand the different components within that system; and how they interact. And that is not something that stackoverflow can give to you; that is something that you have to figure yourself.
answered Oct 3, 2016 at 12:12
A timeout was set by the library and yet it didn’t read anything before the timeout was reached.
This could happen if the other end it is reading from stop for a long time. The library determines what counts as a long time. I would look for any errors logged on the server it is connected to.
answered Oct 3, 2016 at 12:12
Peter LawreyPeter Lawrey
524k77 gold badges749 silver badges1130 bronze badges
refer http://docs.oracle.com/javase/6/docs/api/java/sql/SQLRecoverableException.html!
try to check
-
check input parameters in
Connection con=DriverManager.getConnection(
«jdbc:oracle:thin:@localhost:1521:xe»,»username»,»password»);-
check database account Expiry date
-
try to restart the DataBase
-
try to retry connection
- if still failed try with another Database dsn
-
answered Oct 3, 2016 at 12:32
I’m getting an error in IntelliJ IDEA when im using a thin connection from java to oracle.
My oracle database is in a server and I can ping the server but my code can’t establish connection:
Class.forName("oracle.jdbc.driver.OracleDriver");
connection = DriverManager.getConnection("jdbc:oracle:thin:@server ip:1521:orcl","user","path");
System.out.println("Oracle Registered...");
and error is:
java.sql.SQLRecoverableException: IO Error: Socket read timed out
oracle.net.ns.NetException: Socket read timed out
Bryan
14.7k10 gold badges67 silver badges124 bronze badges
asked Aug 22, 2016 at 12:31
4
It is possible that the network is reachable but the operations take too much time.
Check if you can establish a connection using a standard db client like toad, sql server or squirrel.
If you can use the same paramters in java and it should work.
If you can’t check if another process is using port 1521 on the server.
answered Aug 22, 2016 at 12:34
1
While applying the R12.2 upgrade driver, we faced the issue of WFXLoad.class failing in adworker log but showing up as running on adctrl
Control
Worker Code Context Filename Status
—— ——— —————— ————————— —————
1 Run AutoPatch R120 pl WFXLoad.class Running
2 Run AutoPatch R120 pl WFXLoad.class Running
3 Run AutoPatch R120 pl WFXLoad.class Running
4 Run AutoPatch R120 pl WFXLoad.class Running
5 Run AutoPatch R120 pl WFXLoad.class Running
6 Run AutoPatch R120 pl Wait
7 Run AutoPatch R120 pl WFXLoad.class Running
8 Run AutoPatch R120 pl WFXLoad.class Running
9 Run AutoPatch R120 pl WFXLoad.class Running
10 Run AutoPatch R120 pl Wait
adworker log shows:
Exception in thread «main» java.sql.SQLRecoverableException: IO Error: Socket read timed out
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:482)
at oracle.jdbc.driver.PhysicalConnection.
(PhysicalConnection.java:678)
at oracle.jdbc.driver.T4CConnection.
(T4CConnection.java:238)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:34)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:567)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at oracle.apps.ad.worker.AdJavaWorker.getAppsConnection(AdJavaWorker.java:1041)
at oracle.apps.ad.worker.AdJavaWorker.main(AdJavaWorker.java:276)
Caused by: oracle.net.ns.NetException: Socket read timed out
at oracle.net.ns.Packet.receive(Packet.java:341)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:308)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1222)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:330)
… 8 more
This was happening again and again. The DBAs were suspecting network issue, cluster issue, server issue and all the usual suspects. In Database alert log we saw these errors coming every few seconds:
Fatal NI connect error 12537, connecting to:
(LOCAL=NO)
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: 11-NOV-2014 19:58:19
Tracing not turned on.
Tns error struct:
ns main err code: 12537
TNS-12537: TNS:connection closed
ns secondary err code: 12560
nt main err code: 0
nt secondary err code: 0
nt OS err code: 0
opiodr aborting process unknown ospid (26388) as a result of ORA-609
We tried changing the parameters in sqlnet.ora and listener.ora as instructed in the article:
Troubleshooting Guide for ORA-12537 / TNS-12537 TNS:Connection Closed (Doc ID 555609.1)
Sqlnet.ora: SQLNET.INBOUND_CONNECT_TIMEOUT=180
Listener.ora: INBOUND_CONNECT_TIMEOUT_listener_name=120
However, the errors continued. To rule out any issues in network, I also restarted the network service on Linux:
service network restart
One thing which I noticed was the extra amount of time that the connect was taking 4 seconds:
21:17:38 SQL> conn apps/apps
Connected.
21:17:42 SQL>
Checked from remote app tier and it was same 4 seconds.
Stopped listener and checked on DB server that uses bequeath protocol:
21:18:47 SQL> conn / as sysdba
Connected.
21:18:51 SQL> conn / as sysdba
Connected.
Again it took 4 seconds.
A few days back, I had seen that connect time had increased after turning setting the DB initialization parameter pre_page_sga to true in a different instance. On a hunch, I checked this and indeed pre_page_sga was set to true. I set this back to false:
alter system set pre_page_sga=false scope=spfile;
shutdown immediate;
exit
sqlplus /nolog
conn / as sysdba
startup
SQL> set time on
22:09:46 SQL> conn / as sysdba
Connected.
22:09:49 SQL>
The connections were happening instantly. So I went ahead and resumed the patch after setting:
update fnd_install_processes
set control_code=’W’, status=’W’;
commit;
I restarted the patch and all the workers completed successfully. And the patch was running significantly faster. So I did a search on support.oracle.com to substantiate my solution with official Oracle documentation. I found the following articles:
Slow Connection or ORA-12170 During Connect when PRE_PAGE_SGA init.ora Parameter is Set (Doc ID 289585.1)
Health Check Alert: Consider setting PRE_PAGE_SGA to FALSE (Doc ID 957525.1)
The first article (289585.1) says:
PRE_PAGE_SGA can increase the process startup duration, because every process that starts must access every page in the SGA. This approach can be useful with some applications, but not with all applications. Overhead can be significant if your system frequently creates and destroys processes by, for example, continually logging on and logging off. The advantage that PRE_PAGE_SGA can afford depends on page size.
The second article (957525.1) says:
Having the PRE_PAGE_SGA initialization parameter set to TRUE can significantly increase the time required to establish database connections.
The golden words here are «Overhead can be significant if your system frequently creates and destroys processes by, for example, continually logging on and logging off.». That is exactly what happens when you do adpatch or adop.
Keep this in mind, whenever you do adpatch or adop, make sure that pre_page_sga is set to false. It is possible that you may get the error «java.sql.SQLRecoverableException: IO Error: Socket read timed out» if you don’t. Also the patch will run significantly slower if pre_page_sga is set to true. So set it to false and avoid these issues.
Solution 1
Depending on your environment, there can be many different reasons: it could be a simple network outage between your machine and the database server. But it could also be that there is a congestion on a lower level; and one layer just sits there; all connection threads taken; waiting for some other side to move … that won’t move any more.
In that sense, the unspecific answer to your unspecific question is: identify the different components that exist in your system and that need to communicate with each other in order to deliver the functionality that they are supposed to deliver. When you have that «map»; you start checking each location on that map by its own.
And hint: if you don’t have such a (mental) map yet; well, welcome to the world of professional IT. When you are responsible for a complex system; you simply have to understand the different components within that system; and how they interact. And that is not something that stackoverflow can give to you; that is something that you have to figure yourself.
Solution 2
A timeout was set by the library and yet it didn’t read anything before the timeout was reached.
This could happen if the other end it is reading from stop for a long time. The library determines what counts as a long time. I would look for any errors logged on the server it is connected to.
Solution 3
refer http://docs.oracle.com/javase/6/docs/api/java/sql/SQLRecoverableException.html!
try to check
-
check input parameters in
Connection con=DriverManager.getConnection(
«jdbc:oracle:thin:@localhost:1521:xe»,»username»,»password»);-
check database account Expiry date
-
try to restart the DataBase
-
try to retry connection
- if still failed try with another Database dsn
-
Comments
-
What are the reasons for getting a Socket read timed out Exception in Java?
I’m gettting:
### Cause: java.sql.SQLRecoverableException: IO Error: Socket read timed out ; SQL []; IO Error: Socket read timed out; nested exception is java.sql.SQLRecoverableException: IO Error: Socket read timed out
Recents
I’m facing the same issue. Any sugestions to resolve it?
06-09-20 21:49:04.772 DEBUG com.zaxxer.hikari.pool.HikariPool : HikariCP-ABC — Fill pool skipped, pool is at sufficient level.
06-09-20 21:49:04.772 DEBUG com.zaxxer.hikari.pool.PoolBase : HikariCP-ABC — Closing connection oracle.jdbc.driver.T4CConnection@135c4bab: (connection has passed maxLifetime)
06-09-20 21:49:05.875 DEBUG com.zaxxer.hikari.pool.PoolBase : HikariCP-ABC — Closing connection oracle.jdbc.driver.T4CConnection@686ae288 failed
java.sql.SQLRecoverableException: IO Error: Socket read timed out
at oracle.jdbc.driver.T4CConnection.logoff(T4CConnection.java:919) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.jdbc.driver.PhysicalConnection.close(PhysicalConnection.java:2005) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at com.zaxxer.hikari.pool.PoolBase.quietlyCloseConnection(PoolBase.java:143) ~[HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.HikariPool.lambda$closeConnection$1(HikariPool.java:451) [HikariCP-3.4.5.jar:na]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_241]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_241]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_241]
Caused by: java.net.SocketTimeoutException: Socket read timed out
at oracle.net.nt.TimeoutSocketChannel.read(TimeoutSocketChannel.java:174) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.net.ns.NIOHeader.readHeaderBuffer(NIOHeader.java:82) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.net.ns.NIOPacket.readFromSocketChannel(NIOPacket.java:139) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.net.ns.NIOPacket.readFromSocketChannel(NIOPacket.java:101) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.net.ns.NIONSDataChannel.readDataFromSocketChannel(NIONSDataChannel.java:80) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.jdbc.driver.T4CMAREngineNIO.prepareForReading(T4CMAREngineNIO.java:98) ~[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.T4CTTIfun.receive(T4CTTIfun.java:485) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:252) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.jdbc.driver.T4C7Ocommoncall.doOLOGOFF(T4C7Ocommoncall.java:62) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.jdbc.driver.T4CConnection.logoff(T4CConnection.java:908) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
… 6 common frames omitted
06-09-20 21:49:05.926 DEBUG com.zaxxer.hikari.pool.HikariPool : HikariCP-ABC — Fill pool skipped, pool is at sufficient level.
06-09-20 21:49:05.926 DEBUG com.zaxxer.hikari.pool.PoolBase : HikariCP-ABC — Closing connection oracle.jdbc.driver.T4CConnection@77661966: (connection has passed maxLifetime)
06-09-20 21:49:06.922 DEBUG com.zaxxer.hikari.pool.HikariPool : HikariCP-BH — Pool stats (total=6, active=1, idle=5, waiting=0)
06-09-20 21:49:06.922 DEBUG com.zaxxer.hikari.pool.HikariPool : HikariCP-BH — Fill pool skipped, pool is at sufficient level.
06-09-20 21:49:08.433 DEBUG com.zaxxer.hikari.pool.HikariPool : HikariCP-ABC — Pool stats (total=10, active=1, idle=9, waiting=0)
06-09-20 21:49:08.433 DEBUG com.zaxxer.hikari.pool.HikariPool : HikariCP-ABC — Fill pool skipped, pool is at sufficient level.
06-09-20 21:49:15.250 DEBUG com.zaxxer.hikari.pool.HikariPool : HikariCP-BH — Pool stats (total=10, active=1, idle=9, waiting=0)
06-09-20 21:49:15.250 DEBUG com.zaxxer.hikari.pool.HikariPool : HikariCP-BH — Fill pool skipped, pool is at sufficient level.
06-09-20 21:49:16.574 DEBUG com.zaxxer.hikari.pool.HikariPool : HikariCP-ABC — Pool stats (total=10, active=1, idle=9, waiting=0)
06-09-20 21:49:16.574 DEBUG com.zaxxer.hikari.pool.HikariPool : HikariCP-ABC — Fill pool skipped, pool is at sufficient level.
06-09-20 21:49:19.784 DEBUG com.zaxxer.hikari.pool.PoolBase : HikariCP-ABC — Closing connection oracle.jdbc.driver.T4CConnection@135c4bab failed
java.sql.SQLRecoverableException: IO Error: Socket read timed out
at oracle.jdbc.driver.T4CConnection.logoff(T4CConnection.java:919) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.jdbc.driver.PhysicalConnection.close(PhysicalConnection.java:2005) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at com.zaxxer.hikari.pool.PoolBase.quietlyCloseConnection(PoolBase.java:143) ~[HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.HikariPool.lambda$closeConnection$1(HikariPool.java:451) [HikariCP-3.4.5.jar:na]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_241]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_241]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_241]
Caused by: java.net.SocketTimeoutException: Socket read timed out
at oracle.net.nt.TimeoutSocketChannel.read(TimeoutSocketChannel.java:174) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.net.ns.NIOHeader.readHeaderBuffer(NIOHeader.java:82) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.net.ns.NIOPacket.readFromSocketChannel(NIOPacket.java:139) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.net.ns.NIOPacket.readFromSocketChannel(NIOPacket.java:101) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.net.ns.NIONSDataChannel.readDataFromSocketChannel(NIONSDataChannel.java:80) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.jdbc.driver.T4CMAREngineNIO.prepareForReading(T4CMAREngineNIO.java:98) ~[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.T4CTTIfun.receive(T4CTTIfun.java:485) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:252) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.jdbc.driver.T4C7Ocommoncall.doOLOGOFF(T4C7Ocommoncall.java:62) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.jdbc.driver.T4CConnection.logoff(T4CConnection.java:908) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
… 6 common frames omitted
06-09-20 21:49:19.811 DEBUG com.zaxxer.hikari.pool.HikariPool : HikariCP-ABC — Fill pool skipped, pool is at sufficient level.
06-09-20 21:49:19.811 DEBUG com.zaxxer.hikari.pool.PoolBase : HikariCP-ABC — Closing connection oracle.jdbc.driver.T4CConnection@2e29e860: (connection has passed maxLifetime)
06-09-20 21:49:20.935 DEBUG com.zaxxer.hikari.pool.PoolBase : HikariCP-ABC — Closing connection oracle.jdbc.driver.T4CConnection@77661966 failed
java.sql.SQLRecoverableException: IO Error: Socket read timed out
at oracle.jdbc.driver.T4CConnection.logoff(T4CConnection.java:919) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.jdbc.driver.PhysicalConnection.close(PhysicalConnection.java:2005) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at com.zaxxer.hikari.pool.PoolBase.quietlyCloseConnection(PoolBase.java:143) ~[HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.HikariPool.lambda$closeConnection$1(HikariPool.java:451) [HikariCP-3.4.5.jar:na]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_241]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_241]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_241]
Caused by: java.net.SocketTimeoutException: Socket read timed out
at oracle.net.nt.TimeoutSocketChannel.read(TimeoutSocketChannel.java:174) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.net.ns.NIOHeader.readHeaderBuffer(NIOHeader.java:82) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.net.ns.NIOPacket.readFromSocketChannel(NIOPacket.java:139) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.net.ns.NIOPacket.readFromSocketChannel(NIOPacket.java:101) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.net.ns.NIONSDataChannel.readDataFromSocketChannel(NIONSDataChannel.java:80) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.jdbc.driver.T4CMAREngineNIO.prepareForReading(T4CMAREngineNIO.java:98) ~[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.T4CTTIfun.receive(T4CTTIfun.java:485) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:252) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.jdbc.driver.T4C7Ocommoncall.doOLOGOFF(T4C7Ocommoncall.java:62) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
at oracle.jdbc.driver.T4CConnection.logoff(T4CConnection.java:908) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
… 6 common frames omitted
06-09-20 21:49:20.960 DEBUG com.zaxxer.hikari.pool.HikariPool : HikariCP-ABC — Fill pool skipped, pool is at sufficient level.
06-09-20 21:49:20.961 DEBUG com.zaxxer.hikari.pool.PoolBase : HikariCP-ABC — Closing connection oracle.jdbc.driver.T4CConnection@7230fdc5: (connection has passed maxLifetime)
06-09-20 21:49:23.595 DEBUG com.zaxxer.hikari.pool.HikariPool : HikariCP-BH — Pool stats (total=6, active=1, idle=5, waiting=0)
06-09-20 21:49:23.596 DEBUG com.zaxxer.hikari.pool.HikariPool : HikariCP-BH — Fill pool skipped, pool is at sufficient level.
06-09-20 21:49:25.216 DEBUG com.zaxxer.hikari.pool.HikariPool : HikariCP-ABC — Pool stats (total=6, active=1, idle=5, waiting=0)
06-09-20 21:49:25.216 DEBUG com.zaxxer.hikari.pool.HikariPool : HikariCP-ABC — Fill pool skipped, pool is at sufficient level.
06-09-20 21:49:27.395 DEBUG com.zaxxer.hikari.pool.HikariPool : HikariCP-BH — Pool stats (total=7, active=1, idle=6, waiting=0)
06-09-20 21:49:27.396 DEBUG com.zaxxer.hikari.pool.HikariPool : HikariCP-BH — Fill pool skipped, pool is at sufficient level.
06-09-20 21:49:28.421 DEBUG com.zaxxer.hikari.pool.HikariPool : HikariCP-BH — Pool stats (total=6, active=1, idle=5, waiting=0)
06-09-20 21:49:28.421 DEBUG com.zaxxer.hikari.pool.HikariPool : HikariCP-BH — Fill pool skipped, pool is at sufficient level.
06-09-20 21:49:28.592 DEBUG com.zaxxer.hikari.pool.HikariPool : HikariCP-ABC — Pool stats (total=6, active=1, idle=5, waiting=0)
06-09-20 21:49:28.592 DEBUG com.zaxxer.hikari.pool.HikariPool : HikariCP-ABC — Fill pool skipped, pool is at sufficient level.