When I try to use sockets in my Java application, I get a SocketException:
SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:186)
at java.net.SocketInputStream.read(SocketInputStream.java:200)
at java.io.ObjectInputStream$PeekInputStream.peek(ObjectInputStream.java:2266)
at java.io.ObjectInputStream$BlockDataInputStream.peek(ObjectInputStream.java:2559)
at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2569)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1315)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
at Form.Server.transfer(Server.java:69)
at Form.Server.main(Server.java:53)
java.net.SocketException: Connection reset
Related
I have a weak connection with database server and time consuming query which is sometimes fails with exception:
Caused by: java.sql.SQLException: I/O Error: Socket closed
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2481)
at net.sourceforge.jtds.jdbc.TdsCore.getNextRow(TdsCore.java:805)
at net.sourceforge.jtds.jdbc.JtdsResultSet.next(JtdsResultSet.java:611)
Caused by: java.net.SocketException: Socket closed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:152)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at java.io.DataInputStream.readFully(DataInputStream.java:195)
at net.sourceforge.jtds.jdbc.SharedSocket.readPacket(SharedSocket.java:885)
at net.sourceforge.jtds.jdbc.SharedSocket.getNetPacket(SharedSocket.java:731)
at net.sourceforge.jtds.jdbc.ResponseStream.getPacket(ResponseStream.java:477)
at net.sourceforge.jtds.jdbc.ResponseStream.read(ResponseStream.java:146)
at net.sourceforge.jtds.jdbc.TdsData.readData(TdsData.java:901)
at net.sourceforge.jtds.jdbc.TdsCore.tdsRowToken(TdsCore.java:3175)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2433)
How can connection interruption be handled? currently I have to manually re-run the operation until it executes successfully, maybe it could be done at jdbc driver level
ps socketTimeout property doesn't seem to affect this
Are you sure this is because of query/procedure taking long time ? As Socket closed error normally means something went wrong with the network connection itself, basically something that your driver could not control...
In general, I would suggest to move to a Pool based mechanism, which allows greater control on your persistence layer interaction.
I have a java code that generate and fill tables to MySQL database.
The method is to create a connection to generate a table and then close that connection afterward.
Then create new connection to fill the table and so on.
I have about 14000 table to generate. The problem is that after generating about 800 tables I got this message and I have to restart mysql again.
Is there a cap to the number of connection I could create? is there anyway to increase it? Any Ideas?
Thanks
java.sql.SQLException: Communication link failure: java.net.SocketException, underlying cause: Connection reset
** BEGIN NESTED EXCEPTION **
java.net.SocketException
MESSAGE: Connection reset
STACKTRACE:
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:189)
at java.net.SocketInputStream.read(SocketInputStream.java:121)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read(BufferedInputStream.java:265)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:1449)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1826)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1803)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:2353)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:750)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1627)
at com.mysql.jdbc.Connection.<init>(Connection.java:427)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:395)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at db.DbConnection.establishConnection(DbConnection.java:21)
at db.DbActivities.addToDocSent(DbActivities.java:125)
at db.DbGeneration.main(DbGeneration.java:58)
** END NESTED EXCEPTION **
Using jedis client to save data to redis localhost.
Once I connect to redisHost using jedis, I am not disconnecting as long as I get messages Is that an issue? Tried to change the timeout from default 2000 to 6000 but still the same error!
connecting and sending data:
if (jedis == null)
jedis = new Jedis(redisHost);
if (!jedis.isConnected())
jedis.connect();
if (jedis.isConnected())
jedis.zadd("someKey", doubleTime, "someValue");
following is the stack trace of the error receiving:
redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: Software caused connection abort: socket write error
at redis.clients.jedis.Protocol.sendCommand(Protocol.java:92)
at redis.clients.jedis.Protocol.sendCommand(Protocol.java:72)
at redis.clients.jedis.Connection.sendCommand(Connection.java:80)
at redis.clients.jedis.BinaryClient.zadd(BinaryClient.java:387)
at redis.clients.jedis.Client.zadd(Client.java:327)
at redis.clients.jedis.Jedis.zadd(Jedis.java:1468)
at com.comcast.xre.WebSocketServer.saveLogToDB(WebSocketServer.java:105)
at com.comcast.xre.WebSocketServer.access$000(WebSocketServer.java:27)
at com.comcast.xre.WebSocketServer$1$1.onFullTextMessage(WebSocketServer.java:69)
at io.undertow.websockets.core.AbstractReceiveListener$2.complete(AbstractReceiveListener.java:138)
at io.undertow.websockets.core.AbstractReceiveListener$2.complete(AbstractReceiveListener.java:134)
at io.undertow.websockets.core.BufferedTextMessage.read(BufferedTextMessage.java:87)
at io.undertow.websockets.core.AbstractReceiveListener.readBufferedText(AbstractReceiveListener.java:134)
at io.undertow.websockets.core.AbstractReceiveListener.bufferFullMessage(AbstractReceiveListener.java:72)
at io.undertow.websockets.core.AbstractReceiveListener.onText(AbstractReceiveListener.java:52)
at io.undertow.websockets.core.AbstractReceiveListener.handleEvent(AbstractReceiveListener.java:26)
at io.undertow.websockets.core.AbstractReceiveListener.handleEvent(AbstractReceiveListener.java:15)
at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
at io.undertow.server.protocol.framed.AbstractFramedChannel$FrameReadListener.handleEvent(AbstractFramedChannel.java:632)
at io.undertow.server.protocol.framed.AbstractFramedChannel$FrameReadListener.handleEvent(AbstractFramedChannel.java:618)
at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
at org.xnio.conduits.ReadReadyHandler$ChannelListenerHandler.readReady(ReadReadyHandler.java:66)
at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:87)
at org.xnio.nio.WorkerThread.run(WorkerThread.java:531)
Caused by: java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
at java.net.SocketOutputStream.write(SocketOutputStream.java:159)
at redis.clients.util.RedisOutputStream.flushBuffer(RedisOutputStream.java:31)
at redis.clients.util.RedisOutputStream.write(RedisOutputStream.java:38)
at redis.clients.jedis.Protocol.sendCommand(Protocol.java:78)
... 23 more
Issue was with Jedis connection. It's connected but after few messages, connection is broken.
After each save to DB, I am disconnecting and removing the jedis client completely and creating a new client and connection. Looks awkward but it solves the issue.
I have return a code to read a web page using jsoup-1.7.3.jar, Its working for some websites but giviing Read timed out error for some of the URls....
.
Exception in thread "main" java.net.SocketTimeoutException: Read timed
out at java.net.SocketInputStream.socketRead0(Native Method) at
java.net.SocketInputStream.read(SocketInputStream.java:152) at
java.net.SocketInputStream.read(SocketInputStream.java:122) at
java.io.BufferedInputStream.fill(BufferedInputStream.java:235) at
java.io.BufferedInputStream.read1(BufferedInputStream.java:275) at
java.io.BufferedInputStream.read(BufferedInputStream.java:334) at
sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687) at
sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:633) at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1323)
at
java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468)
at
org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:443)
at
org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:424)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:178)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:167) at
Main.main(Main.java:10)
As ooxi mentioned, you can set a timeout
Jsoup.connect("").timeout(5*1000).get() //which sets timeout for 5 seconds
Edit: You can specify the timeout though the Connection
Connection connection = Jsoup.connect("");
connection.timeout(5*1000); // which sets timeout for 5 seconds
Before calling .get you can set a timeout for example
Jsoup.connect(url).timeout(0).get();
Have a look at the JavaDocs of Jsoup and Connection
This question already has answers here:
java.net.SocketException: Connection reset
(14 answers)
Closed 7 years ago.
I am getting the following error frequently while retrieving file object from database column. How can I resolve this problem?
May 8, 2009 3:18:14 PM org.apache.catalina.core.StandardHostValve status
WARNING: Exception Processing ErrorPage[errorCode=404, location=/error.jsp]
ClientAbortException: java.net.SocketException: Connection reset by peer: socket write error
at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:327)
at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:293)
at org.apache.catalina.connector.Response.flushBuffer(Response.java:537)
at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:286)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Unknown Source)
Caused by: java.net.SocketException: Connection reset by peer: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(Unknown Source)
at java.net.SocketOutputStream.write(Unknown Source)
at org.apache.coyote.http11.InternalOutputBuffer.realWriteBytes(InternalOutputBuffer.java:746)
at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:433)
at org.apache.coyote.http11.InternalOutputBuffer.flush(InternalOutputBuffer.java:304)
at org.apache.coyote.http11.Http11Processor.action(Http11Processor.java:991)
at org.apache.coyote.Response.action(Response.java:182)
at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:322)
... 13 more
Your HTTP client disconnected.
This could have a couple of reasons:
Responding to the request took too long, the client gave up
You responded with something the client did not understand
The end-user actually cancelled the request
A network error occurred
... probably more
You can fairly easily emulate the behavior:
URL url = new URL("http://example.com/path/to/the/file");
int numberOfBytesToRead = 200;
byte[] buffer = new byte[numberOfBytesToRead];
int numberOfBytesRead = url.openStream().read(buffer);
Your log indicates ClientAbortException, which occurs when your HTTP client drops the connection with the server and this happened before server could close the server socket Connection.
I have got this error on open page from Google Cache.
I think, cached page(client) disconnecting on page loading.
You can ignore this error log with try-catch on filter.
Windows Firewall could cause this exception, try to disable it or add a rule for port or even program (java)