Tag Archives: java.net.NoRouteToHostException: Cannot assign requested address

java.net.NoRouteToHostException: Cannot assign requested address

Open source software supply chain lighting plan, waiting for you>>>

At the beginning of today’s stress test, there were many exceptions, all of which were java.net.noroutetohostexception: cannot assign requested address

According to the information on the Internet, it is due to the exhaustion of the client connection port allocated by Linux and the failure to establish a socket connection. Although the socket is normally closed, the port is not released immediately, but is in time_ Wait state, wait for 60s by default before releasing.

Check the range of client connection ports supported by Linux, that is, 28232 ports

cat /proc/sys/net/ipv4/ip_ local_ port_ range

32768 – 61000

resolvent:

1. Reduce the waiting time after port release, which is 60 s by default and 15 ~ 30 s by modification

echo 30 >/proc/sys/net/ipv4/tcp_ fin_ timeout

2. Modify the TCP/IP protocol configuration by configuring/proc/sys/net/IPv4/TCP_ tw_ Reset, default to 0, modify to 1, release time_ The wait port is used for new connections.

echo 1 >/proc/sys/net/ipv4/tcp_ tw_ reuse

3. Modify the TCP/IP protocol configuration to recycle socket resources quickly. The default value is 0 and the value is 1

echo 1 >/proc/sys/net/ipv4/tcp_ tw_ recycle

Through the above three adjustments, the pressure test runs normally.

Java.net.noroutetohostexception: cannot assign requested address

Open source software supply chain lighting plan, waiting for you>>>

Question:

Error reason: because the client connection port allocated by Linux is exhausted, the socket connection cannot be established. Although the socket is closed normally, the port is not released immediately, but is in time_ Wait status. By default, wait for 60s and release
check the range of client connection ports supported by Linux, that is, 28232 portscat /proc/sys/net/ipv4/ip_ local_ port_ range
32768 - 61000

Solution:
1. Reduce the waiting time after port release, which is 60 s by default and 15 ~ 30 s by modificationecho 30 >/proc/sys/net/ipv4/tcp_ fin_ Timeout
2. Modify the TCP/IP protocol configuration by configuring /proc/sys/net/IPv4/TCP_ tw_ Reuse , default to 0, modify to 1, release time_ Wait port for new connectionecho 1 >/proc/sys/net/ipv4/tcp_ tw_ Reuse
3. Modify CTP/IP protocol configuration to recycle socket resources quickly. The default value is 0. Modify to 1echo 1 >/proc/sys/net/ipv4/tcp_ tw_ recycle

https://blog.csdn.net/weixin_ 43757847/article/details/88188091

https://my.oschina.net/shichangcheng/blog/1560864

https://stackoverflow.com/questions/32282112/error-setting-net-ipv4-tcp-tw-reuse-net-ipv4-tcp-tw-recycle-in-sysctl-conf

Wei Chengjun helped to find it

Postscript:

There’s a solution

Modify httpclient4. Idletimeout = & lt; in JMeter. Properties; timeinms> Set the time you think is reasonable. Generally, it can be set to 10-60s (it means the connection will be disconnected after 10s of free time). Note that the unit here is Ms

Reference: https://blog.csdn.net/Stesthu/article/details/87968927

Postscript:

I misunderstood this concept a little. After establishing a long connection, httpclient4.idletimeout means that the long link port will be disconnected as soon as it is idle. For example, the server will be disconnected directly when it is idle before it responds, resulting in an error. Here, the time should be set a little longer, keep a long connection, keep a connection all the time

Reference: https://www.cnblogs.com/kaibindirver/p/11957645.html To use a long connection, you need to configure the requester. See the connection section

Check whether the port is used up. Netstat – an check whether there is a port in timewait

https://i-beta.cnblogs.com/posts/edit-done; postId=11956755

Postscript:

After configuring a long connection, there will still be an error. Finally, you need to modify the release time of the port on the Mac https://www.cnblogs.com/kaibindirver/p/11958506.html

Moreover, when JMeter simulates sending a request, remember to add

C onnection:keep-alive Stay connected