I searched all over the Chinese and English websites, searched every corner I could find, and found the cause and principle of the malfunction, as well as how to deal with it. I recorded it here. I hope it can help friends in need and avoid detours. Above Let’s sort out the content:
connection reset by peer problem summary and solution
1. The number of concurrent connections of the server exceeds its capacity, and the server will close some of the connections
If you know the number of concurrent clients actually connected to the server, there is no If the load capacity of the server is exceeded, there may be a virus or Trojan horse, causing abnormal network traffic.
Solution: You can use the netstat -an command to check the network connection status.
2. The client closed the browser, but the server is still sending data to the client
3. The browser pressed Stop
These two situations generally will not affect the server, but if there is no special handling of the abnormal information , it is possible that this exception appears repeatedly in the server's log file, causing the server log file to be too large and affecting the operation of the server.
Solution: You can use try...catch to capture the exception that caused the exception, and then do not output or only output a prompt message to avoid outputting all exception information.
4. Firewall problem
If the network connection passes through the firewall, and the firewall generally has a timeout mechanism, when the network connection does not transmit data for a long time, the TCP session will be closed. After closing, reading and writing will cause abnormal.
Solution: If turning off the firewall solves the problem, you need to reconfigure the firewall or write your own program to implement long TCP connections.
To implement a long TCP connection, you need to define the heartbeat protocol yourself. Every once in a while, a heartbeat protocol is sent and the two parties maintain the connection.
5. JSP buffer problem
The default cache of JSP pages is 8K. When the JSP page data is relatively large, it is possible that the JSP is not completely transmitted to the browser.
Solution: You can adjust the buffer size appropriately.
<%@ page buffer="100k"%>