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
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战