Java.net.SocketException:Connection Reset Solution _java

Source: Internet
Author: User

Since the Seotcs system November 24 updated SEO scoring algorithm, has been bothering me a problem occurred, Java data Job tasks, in the implementation process will often report the following error:

"2011-12-03 18:00:32 defaulthttpclient [INFO] I/O exception (java.net.SocketException) caught when processing Request:co Nnection Reset by Peer:socket write error
2011-12-03 18:00:32 defaulthttpclient [INFO] retrying request "...

To this end, I searched some websites in english and Chinese, searched every corner that can find, found the principle of this situation, the Java exception on both the client and server side can occur, causing the exception for two reasons:

1, if one end of the socket is closed (or active shutdown, or because of an unexpected exit caused by the shutdown), the other end is still sending data, the first packet sent to throw the exception (Connect reset by peer).

2, one end exits, but the connection is not closed when you exit, and the other end throws the exception if you read the data from the connection (Connection reset). Simply speaking, it is caused by read and write operations after a disconnected connection.

So I simply think that by setting some socket timeout time, you can solve:

But after setting up the situation remains that way.

This problem has been bothering for several days, every day in the thinking and comparative testing, in order to find the reason for this code, I can't help thinking, the same number of keywords in the premise, why the batch query ranking data without error, and the recent frequent error, this is why? is the requested interface site shielding our server IP? This reason is not very sufficient, must be in the program somewhere there is no reasonable release of connection connection caused!

Under the guidance of this idea, through a few days of continuous fighting and practice, today finally found the nature of the problem, that is the timer method caused! This is the case, these days, I manually triggered some batch tasks, found in the filter ranked value of 100, the Java java.net.SocketException:Connection reset this error will always be thrown, and the screen is particularly powerful, In a careful contrast to this timer code,

After, finally suddenly wake up, yes! This is the problem here, I will analyze it myself:

A function value, the value that it returns is a critical value, but in my timer's method, it is determined that the returned value, if it is a critical value, will force it to continue executing that method within 10 seconds, and this method is to obtain a specific data of the source code in the page. Each time this method executes consumes dozens of milliseconds, which is equivalent to creating a socket connection at this time, but because it always returns that threshold, this method will continue to establish a socket connection for 10 seconds to get the data. If this method is approximately 80ms per execution time (tested, each such method executes for about 80 milliseconds), a 10*1000/80 = 125 socket connection is established within 10 seconds. That is, 12.5 socket connections are established per second, plus, because this is a filtered program, a number of critical values will continue to appear together, so, in a short few seconds, on the same site page of the number of sockets will soar high, to hundreds of or even thousands, resulting in waiting for processing the number of requests connected too high:

Why did you use this timer method to make a method do a few more times, the reason is to get a stable value of data, but now think, bring the negative impact of how big the cost, the effect is not to be underestimated, but after a few days of comprehensive analysis and testing, finally found the culprit, After the problem is solved, the heart, all of a sudden, you can sleep at ease ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.