荣耀之链论坛

 找回密码
 立即注册
搜索
查看: 1044|回复: 2

由于系统缓冲区空间不足或队列已满,不能执行套接字上...

[复制链接]

1326

主题

2373

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
10267
发表于 2022-3-10 16:07 | 显示全部楼层 |阅读模式
异常信息:
System.Net.Sockets.SocketException (0x80004005): 由于系统缓冲区空间不足或队列已满,不能执行套接字上的操作。 192.168.0.187:22

   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
   at Tamir.SharpSsh.java.net.Socket..ctor(String host, Int32 port)
   at Tamir.SharpSsh.jsch.Util.createSocket(String host, Int32 port, Int32 timeout)
错误描述:
服务器上部署有  WebService、处理服务:WebService有客户端轮询调用;处理服务也轮询数据库,进行相关处理后上传文件到SFTP上。


解决方法:
修改两个注册表:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters\MaxUserPort  如果没有,则手动创建 DWord(32位)  ”数值数据“改为十进制65534 或者认为适当的值。

此值表示 用户最大使用的端口数量,默认为5000。



HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters\TCPTimedWaitDelay 如果没有,则手动创建 DWord(32位)  ”数值数据“改为十进制30 或者你认为适当的值。

此值表示一个关闭后的端口等待多久之后可以重新使用,默认为120秒,也就是2分钟才可以重新使用。
————————————————
版权声明:本文为CSDN博主「NuClear」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/s_nuclear/article/details/25898597
回复

使用道具 举报

1326

主题

2373

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
10267
 楼主| 发表于 2022-3-10 16:08 | 显示全部楼层
开传奇遇到这个问题 后来按照操作增加了这2个键值就没问题了
托管的服务器开了几天以后想开二区 结果死活不行 我估计就是引擎设计的有问题
回复 支持 反对

使用道具 举报

1326

主题

2373

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
10267
 楼主| 发表于 2022-3-15 14:29 | 显示全部楼层
https://cloud.tencent.com/develo ... icle.detail.1025062

https://www.thegeekdiary.com/hig ... tat-command-output/

BOUND

Bound, ready to connect or listen.

CLOSED

Closed. The socket is not being used.

CLOSING

Closed, then remote shutdown; awaiting acknowledgment.

CLOSE_WAIT

Remote shutdown; waiting for the socket to close.

ESTABLISHED

Connection has been established.

FIN_WAIT_1

Socket closed; shutting down connection.

FIN_WAIT_2

Socket closed; waiting for shutdown from remote.

IDLE

Idle, opened but not bound.

LAST_ACK

Remote shutdown, then closed; awaiting acknowledgment.

LISTEN

Listening for incoming connections.

SYN_RECEIVED

Active/initiate synchronization received and the connection under way

SYN_SENT

Actively trying to establish connection.

TIME_WAIT

Wait after close for remote shutdown retransmission.

'CLOSE_WAIT' state means the other end of the connection has been closed while the local end is still waiting for the application to close. The local end-point has received a connection termination request and acknowledged it e.g. a passive close has been performed and the local end-point needs to perform an active close to leave this state.

CLOSE_WAIT indicates that the remote endpoint (other side of the connection) has closed the connection.

TIME_WAIT indicates that local endpoint (this side) has closed the connection.

Details
‘CLOSE_WAIT’ state on tcp connections occurs if the system has not received a close system call from the application, after having received notification (‘FIN’ packet) from the other system that it has closed its endpoint. In other words it means that the local end of the connection has received ‘FIN’ from the other end, but the OS is waiting for the program at the local end to actually close its connection.

The problem is that a program running on the local machine is not closing the socket. It is not a TCP tuning issue. A connection can stay in ‘CLOSE_WAIT’ forever while the program holds the connection open. So mostly this issue happens due to an application bug. However if TCP/IP parameters are not properly set, closed TCP/IP connections will stay for a very long time in various ‘CLOSE’ states which take file descriptors from the process. In order to solve this problem, sometimes it is necessary to tune TCP/IP parameters, so that TCP/IP connections are closed in a short amount of time.

修改Time_Wait参数的方法 (在服务端修改,需要重启机器)

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /v "TcpTimedWaitDelay" /t REG_DWORD /d 30 /f

<2012R2和Win8.1的系统,执行:

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /v "TcpTimedWaitDelay" /t REG_DWORD /d 30 /f

≥2012R2和Win8.1的系统,执行:

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /v "TcpTimedWaitDelay" /t REG_DWORD /d 2 /f

Key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters

Value:

TcpTimedWaitDelay

Data Type:

REG_DWORD

Range:

Windows Server 2012 and earlier: 30-300 (decimal)Windows 8 and earlier: 30-300 (decimal)Windows Server 2012 R2 and later: 2-300 (decimal)Windows 8.1 and later: 2-300 (decimal)

Default value:

0x78 (120 decimal)

Recommended value:

30

Value exists by default?

No, needs to be added.

Close_Wait引发的问题:

Close_Wait数量过多会引起网络可用连接少、网络性能下降,并占用系统非换页内存。 尤其是在有连接池的情况下(比如HttpRequest)会耗尽连接池的网络连接数,导致无法建立网络连接。

解决CLOSE_WAIT的方法:(在客户端修改)

分析:

1、一般原因都是TCP连接没有调用关闭方法。需要应用来处理网络链接关闭。

2、对于Web请求出现这个原因,经常是因为Response的BodyStream没有调用Close

比如Widnows下:

使用HttpWebRequest 一定要保证GetRequestStream和GetResponse对象关闭,否则容易造成连接处于CLOSE_WAIT状态。

3、TCP的KeepLive功能,可以让操作系统替我们自动清理掉CLOSE_WAIT的连接。

但是KeepAliveTime在Windows操作系统下默认是7200秒,也就是2个小时才清理一次,往往满足不了需求,可以调小该数值。

Windows下的调整方法为

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters]下的以下三个参数:

KeepAliveTime,设置其值为300000(单位为毫秒,300000代表5分钟)

KeepAliveInterval,设置其值为1000(单位为毫秒,1000代表1秒)

TcpMaxDataRetransmissions,设置其值为4

具体执行:管理员身份运行如下命令(重启生效)

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /v "KeepAliveTime" /d 300000 /t REG_DWORD /f

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /v "KeepAliveInterval" /d 1000 /t REG_DWORD /f

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /v "TcpMaxDataRetransmissions" /d 4 /t REG_DWORD /f

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /v "TcpTimedWaitDelay" /t REG_DWORD /d 2 /f

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /v "TcpMaxConnectRetransmissions" /t REG_DWORD /d 2 /f

或者以下另存为close_wait.reg导入系统即可(重启生效)

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters]

"KeepAliveTime"=dword:000493e0

"KeepAliveInterval"=dword:000003e8

"TcpMaxDataRetransmissions"=dword:00000004

"TcpTimedWaitDelay"=dword:00000002

"TcpMaxConnectRetransmissions"=dword:00000002

参考资料:

KeepAliveInterval

https://docs.microsoft.com/en-us ... 000-server/cc957548(v=technet.10)

KeepAliveTime

https://docs.microsoft.com/en-us ... 000-server/cc957549(v=technet.10)

TcpMaxConnectRetransmissions

https://docs.microsoft.com/en-us ... 000-server/cc938209(v=technet.10)

TcpMaxDataRetransmissions

https://docs.microsoft.com/en-us ... 000-server/cc938210(v=technet.10)

TcpTimedWaitDelay

https://docs.microsoft.com/en-us ... 000-server/cc938217(v=technet.10)

EnableDeadGWDetect

https://docs.microsoft.com/en-us ... 000-server/cc960464(v=technet.10)

https://www.ibm.com/support/page ... p-keepalive-windows

https://community.progress.com/s ... -IP-Port-Exhaustion

统计closewait的powershell命令

(get-nettcpconnection -state closewait).count

(netstat -ano).count


cmd下netstat -ano|find /c "CLOSE_WAIT"

原创声明,本文系作者授权云+社区发表,未经许可,不得转载。

如有侵权,请联系 yunjia_community@tencent.com 删除。

云服务器Windows ServerWindows
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

荣耀之链

GMT+8, 2025-6-18 05:48 , Processed in 0.013678 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表