Cannot assign requested address error resolution

found that a cannot assign requested address error occurred during recent pressure testing of the TCP service and looked up

on the network

for the following reasons:

client side frequently establishes the connection, but the port release is slow, resulting in no available port when establishing the new connection.

you can see many TIME_WAIT state connections

through netstat

netstat -ae | grep TIME_WAIT

server in the presence of a large number of short connections, Linux TCP stacks typically generate a large number of TIME_WAIT state sockets, sometimes surprisingly large. This increase takes up the system kernel, which is not infinite.


by modifying the following system parameters to solve (/ etc/sysctl. Conf) :

sysctl -w net.ipv4.tcp_fin_timeout=30  #修改系統默认的TIMEOUT时间,默认为60s 
sysctl -w net.ipv4.tcp_timestamps=1    #修改tcp/ip协议配置, 通过配置/proc/sys/net/ipv4/tcp_tw_resue, 默认为0,修改为1,释放TIME_WAIT端口给新连接使用
sysctl -w net.ipv4.tcp_tw_recycle=1     #修改tcp/ip协议配置,快速回收socket资源,默认为0,修改为1:
sysctl -w net.ipv4.tcp_tw_reuse = 1     #允许端口重用


Read More: