Error during WebSocket handshake: Unexpected response code: 502 偶尔出现此情况

在做ws握手时 发现 连接失败  可以查看所在服务代理的nginx 日志是否存在 连接异常的情况:

2022/08/25 11:24:29 [error] 19891#0: *476329 connect() failed (111: Connection refused) while connecting to upstream, client: 119.98.190.115, server: test-app.whgxwl.com, request: "GET /wss HTTP/1.1", upstream: "http://127.0.0.1:10026/wss", host: "test-app.whgxwl.com"
2022/08/25 11:29:17 [crit] 19890#0: *476582 SSL_shutdown() failed (SSL: error:140E0197:SSL routines:SSL_shutdown:shutdown while in init) while SSL handshaking, client: 172.104.11.214, server: 0.0.0.0:443
2022/08/25 11:40:24 [error] 19890#0: *476895 connect() failed (111: Connection refused) while connecting to upstream, client: 220.249.90.140, server: test-app.whgxwl.com, request: "GET /wss HTTP/1.1", upstream: "http://127.0.0.1:10026/wss", host: "test-app.whgxwl.com"
2022/08/25 11:40:24 [error] 19890#0: *476896 connect() failed (111: Connection refused) while connecting to upstream, client: 220.249.90.140, server: test-app.whgxwl.com, request: "GET /wss HTTP/1.1", upstream: "http://127.0.0.1:10026/wss", host: "test-app.whgxwl.com"
2022/08/25 11:40:24 [error] 19890#0: *476899 connect() failed (111: Connection refused) while connecting to upstream, client: 220.249.90.140, server: test-app.whgxwl.com, request: "GET /wss HTTP/1.1", upstream: "http://127.0.0.1:10026/wss", host: "test-app.whgxwl.com"
2022/08/25 11:40:24 [error] 19890#0: *476900 connect() failed (111: Connection refused) while connecting to upstream, client: 220.249.90.140, server: test-app.whgxwl.com, request: "GET /wss HTTP/1.1", upstream: "http://127.0.0.1:10026/wss", host: "test-app.whgxwl.com"

1、是否属于tcp连接数突增 TIME_WAIT积压

# netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
TIME_WAIT 35423
CLOSE_WAIT 23602
SYN_SENT 62
FIN_WAIT1 61
FIN_WAIT2 259
ESTABLISHED 7543
SYN_RECV 3
CLOSING 35
LAST_ACK 507

发现WAIT数量过高,TCP连接断开后,会以TIME_WAIT状态保留一定的时间,然后才会释放端口。当并发请求过多的时候,就会产生大量的TIME_WAIT状态的连接,无法及时断开的话,会占用大量的端口资源和服务器资源,导致很多连接被拒绝了。

解决方式:https://blog.csdn.net/fomin_zhu/article/details/104978030

转载地址:https://blog.csdn.net/fomin_zhu/article/details/104978030

 

posted @ 2023-10-07 10:20  Paul15963  阅读(827)  评论(0编辑  收藏  举报