nginx代理socket链接集群后,频繁断开重连

目录

    • 一、场景
    • 二、具体表现如下
    • 三、nginx代理配置
    • 四、nginx报错信息
      • 1、nginx错误日志
      • 2、nginx访问日志
    • 五、服务端socket链接日志
    • 六、原因
    • 七、解决


一、场景

nginx使用集群模式代理多个socket链接,socket链接频繁断开重连


二、具体表现如下

在这里插入图片描述


三、nginx代理配置

## socket集群
upstream test_socket {server 192.168.1.233:9901;server 192.168.1.243:9901;
}server {listen       8600;server_name  localhost;location / {root   html;index  index.html index.htm;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}## socket.iolocation ~* /socket.io/* {proxy_pass http://test_socket;# WebScoket Supportproxy_http_version 1.1;# webscoekt超时时间,如果没有做心跳之类的动作需要配置proxy_read_timeout 700s;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";proxy_set_header Origin xxx;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header Host $http_host;proxy_set_header X-NginX-Proxy true;break;}
}

四、nginx报错信息

1、nginx错误日志

2023/08/30 11:22:19 [error] 192424#0: *109446 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "POST /socket.io/?EIO=3&transport=polling&t=Of4Tg3l&sid=75b5dd34-7636-4683-8848-402ba4a5d0d4 HTTP/1.1", upstream: "http://192.168.1.243:9901/socket.io/?EIO=3&transport=polling&t=Of4Tg3l&sid=75b5dd34-7636-4683-8848-402ba4a5d0d4", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"
2023/08/30 11:22:19 [error] 192424#0: *109450 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "POST /socket.io/?EIO=3&transport=polling&t=Of4Tg3u&sid=75b5dd34-7636-4683-8848-402ba4a5d0d4 HTTP/1.1", upstream: "http://192.168.1.243:9901/socket.io/?EIO=3&transport=polling&t=Of4Tg3u&sid=75b5dd34-7636-4683-8848-402ba4a5d0d4", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"
2023/08/30 11:22:20 [error] 192424#0: *109453 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "POST /socket.io/?EIO=3&transport=polling&t=Of4TgF_&sid=fe446904-412b-487b-b0ca-fe3b153218c5 HTTP/1.1", upstream: "http://192.168.1.243:9901/socket.io/?EIO=3&transport=polling&t=Of4TgF_&sid=fe446904-412b-487b-b0ca-fe3b153218c5", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"
2023/08/30 11:22:20 [error] 192424#0: *109451 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "POST /socket.io/?EIO=3&transport=polling&t=Of4TgG7&sid=fe446904-412b-487b-b0ca-fe3b153218c5 HTTP/1.1", upstream: "http://192.168.1.243:9901/socket.io/?EIO=3&transport=polling&t=Of4TgG7&sid=fe446904-412b-487b-b0ca-fe3b153218c5", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"
2023/08/30 11:22:21 [error] 192424#0: *109492 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "GET /socket.io/?EIO=3&transport=polling&t=Of4TgYr&sid=e52704e9-f99c-45df-89c1-1d2424277a77 HTTP/1.1", upstream: "http://192.168.1.243:9901/socket.io/?EIO=3&transport=polling&t=Of4TgYr&sid=e52704e9-f99c-45df-89c1-1d2424277a77", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"
2023/08/30 11:22:22 [error] 192424#0: *109497 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "POST /socket.io/?EIO=3&transport=polling&t=Of4Tgk1&sid=f5bfb349-17bf-4a81-853c-23c52acf2b35 HTTP/1.1", upstream: "http://192.168.1.233:9901/socket.io/?EIO=3&transport=polling&t=Of4Tgk1&sid=f5bfb349-17bf-4a81-853c-23c52acf2b35", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"
2023/08/30 11:22:22 [error] 192424#0: *109505 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "POST /socket.io/?EIO=3&transport=polling&t=Of4Tgk5&sid=f5bfb349-17bf-4a81-853c-23c52acf2b35 HTTP/1.1", upstream: "http://192.168.1.233:9901/socket.io/?EIO=3&transport=polling&t=Of4Tgk5&sid=f5bfb349-17bf-4a81-853c-23c52acf2b35", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"
2023/08/30 11:22:23 [error] 192424#0: *109517 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "GET /socket.io/?EIO=3&transport=polling&t=Of4Tg_e&sid=b5c9c6a9-f43c-4455-a001-d2dc6f01c39c HTTP/1.1", upstream: "http://192.168.1.233:9901/socket.io/?EIO=3&transport=polling&t=Of4Tg_e&sid=b5c9c6a9-f43c-4455-a001-d2dc6f01c39c", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"
2023/08/30 11:22:23 [error] 192424#0: *109507 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "POST /socket.io/?EIO=3&transport=polling&t=Of4Tg_i&sid=b5c9c6a9-f43c-4455-a001-d2dc6f01c39c HTTP/1.1", upstream: "http://192.168.1.233:9901/socket.io/?EIO=3&transport=polling&t=Of4Tg_i&sid=b5c9c6a9-f43c-4455-a001-d2dc6f01c39c", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"
2023/08/30 11:22:24 [error] 192424#0: *109526 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "GET /socket.io/?EIO=3&transport=polling&t=Of4ThLE&sid=a7896c79-b510-4a37-bf65-8eded388bef3 HTTP/1.1", upstream: "http://192.168.1.233:9901/socket.io/?EIO=3&transport=polling&t=Of4ThLE&sid=a7896c79-b510-4a37-bf65-8eded388bef3", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"
2023/08/30 11:22:24 [error] 192424#0: *109531 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "POST /socket.io/?EIO=3&transport=polling&t=Of4ThLJ&sid=a7896c79-b510-4a37-bf65-8eded388bef3 HTTP/1.1", upstream: "http://192.168.1.233:9901/socket.io/?EIO=3&transport=polling&t=Of4ThLJ&sid=a7896c79-b510-4a37-bf65-8eded388bef3", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"
2023/08/30 11:22:26 [error] 192424#0: *109533 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "POST /socket.io/?EIO=3&transport=polling&t=Of4Thcj&sid=ee4e2bf1-fc65-4652-99f5-d60e91e88ac3 HTTP/1.1", upstream: "http://192.168.1.233:9901/socket.io/?EIO=3&transport=polling&t=Of4Thcj&sid=ee4e2bf1-fc65-4652-99f5-d60e91e88ac3", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"
2023/08/30 11:22:26 [error] 192424#0: *109541 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "POST /socket.io/?EIO=3&transport=polling&t=Of4Thco&sid=ee4e2bf1-fc65-4652-99f5-d60e91e88ac3 HTTP/1.1", upstream: "http://192.168.1.233:9901/socket.io/?EIO=3&transport=polling&t=Of4Thco&sid=ee4e2bf1-fc65-4652-99f5-d60e91e88ac3", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"
2023/08/30 11:22:26 [error] 192424#0: *109543 upstream prematurely closed connection while reading upstream, client: 192.168.4.10, server: localhost, request: "POST /socket.io/?EIO=3&transport=polling&t=Of4Thkr&sid=06815ca2-fd5d-4d83-87f3-344dac41a60a HTTP/1.1", upstream: "http://192.168.1.233:9901/socket.io/?EIO=3&transport=polling&t=Of4Thkr&sid=06815ca2-fd5d-4d83-87f3-344dac41a60a", host: "192.168.1.233:8600", referrer: "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1"

2、nginx访问日志

192.168.4.10 - - [30/Aug/2023:14:10:29 +0800] "GET /socket.io/?EIO=3&transport=websocket&sid=44896d85-8569-42c3-adc6-7ce49132f6f0 HTTP/1.1" 101 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:29 +0800] "GET /socket.io/?EIO=3&transport=polling&t=Of549Rf&sid=44896d85-8569-42c3-adc6-7ce49132f6f0 HTTP/1.1" 200 42 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:29 +0800] "POST /socket.io/?EIO=3&transport=polling&t=Of549Rk&sid=44896d85-8569-42c3-adc6-7ce49132f6f0 HTTP/1.1" 500 0 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:29 +0800] "POST /socket.io/?EIO=3&transport=polling&t=Of549Rp&sid=44896d85-8569-42c3-adc6-7ce49132f6f0 HTTP/1.1" 200 39 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:29 +0800] "GET /socket.io/?EIO=3&transport=polling&t=Of549Rk.0&sid=44896d85-8569-42c3-adc6-7ce49132f6f0 HTTP/1.1" 500 0 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:30 +0800] "GET /socket.io/?EIO=3&transport=polling&t=Of549ic HTTP/1.1" 200 147 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:30 +0800] "GET /socket.io/?EIO=3&transport=websocket&sid=1c735e86-00ba-4125-9cbf-c3923feda84e HTTP/1.1" 101 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:30 +0800] "GET /socket.io/?EIO=3&transport=polling&t=Of549ik&sid=1c735e86-00ba-4125-9cbf-c3923feda84e HTTP/1.1" 200 42 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:30 +0800] "POST /socket.io/?EIO=3&transport=polling&t=Of549ip&sid=1c735e86-00ba-4125-9cbf-c3923feda84e HTTP/1.1" 500 0 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:30 +0800] "POST /socket.io/?EIO=3&transport=polling&t=Of549iu&sid=1c735e86-00ba-4125-9cbf-c3923feda84e HTTP/1.1" 500 0 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:31 +0800] "GET /socket.io/?EIO=3&transport=polling&t=Of549vb HTTP/1.1" 200 147 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:31 +0800] "GET /socket.io/?EIO=3&transport=websocket&sid=cb931664-f714-4e01-8c60-d1dd515473a3 HTTP/1.1" 101 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:31 +0800] "GET /socket.io/?EIO=3&transport=polling&t=Of549vj&sid=cb931664-f714-4e01-8c60-d1dd515473a3 HTTP/1.1" 200 42 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:31 +0800] "POST /socket.io/?EIO=3&transport=polling&t=Of549vo&sid=cb931664-f714-4e01-8c60-d1dd515473a3 HTTP/1.1" 500 0 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:31 +0800] "POST /socket.io/?EIO=3&transport=polling&t=Of549vw&sid=cb931664-f714-4e01-8c60-d1dd515473a3 HTTP/1.1" 500 0 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:32 +0800] "GET /socket.io/?EIO=3&transport=polling&t=Of54A3O HTTP/1.1" 200 146 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:32 +0800] "GET /socket.io/?EIO=3&transport=websocket&sid=e9808cde-0f07-4539-9b60-20bf099e12f4 HTTP/1.1" 101 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:32 +0800] "GET /socket.io/?EIO=3&transport=polling&t=Of54A3V&sid=e9808cde-0f07-4539-9b60-20bf099e12f4 HTTP/1.1" 200 42 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
192.168.4.10 - - [30/Aug/2023:14:10:32 +0800] "POST /socket.io/?EIO=3&transport=polling&t=Of54A3a&sid=e9808cde-0f07-4539-9b60-20bf099e12f4 HTTP/1.1" 500 0 "http://192.168.1.233:8600/FS_WEB_ASS/cloud/app_websocket.html?originId=1&vdnId=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"

五、服务端socket链接日志

2023-08-30 14:28:59.128 - [ERROR] - [nioEventLoopGroup-3-16] - [c.c.socketio.transport.PollingTransport - line:147]: c40dc987-8544-47b5-958b-3952967f1d47 is not registered. Closing connection
2023-08-30 14:28:59.147 - [ERROR] - [nioEventLoopGroup-3-17] - [c.c.socketio.transport.PollingTransport - line:168]: dc0fa35e-35a3-45fd-9a9e-26ba4746b4c8 is not registered. Closing connection
2023-08-30 14:28:59.588 - [INFO ] - [nioEventLoopGroup-3-18] - [com.xxx.socket.hander.SocketService - line:60]: 192.168.1.233:52116 移动客户端接入!
2023-08-30 14:28:59.588 - [INFO ] - [nioEventLoopGroup-3-18] - [com.xxx.socket.interceptor.EventListener - line:40]: 建立连接
2023-08-30 14:28:59.599 - [INFO ] - [nioEventLoopGroup-3-19] - [com.xxx.socket.hander.SocketService - line:68]: 192.168.1.233:52116 移动客户端已断开连接!
2023-08-30 14:28:59.599 - [INFO ] - [nioEventLoopGroup-3-19] - [com.xxx.socket.interceptor.EventListener - line:60]: 关闭连接。。。。。。。。。
2023-08-30 14:28:59.760 - [INFO ] - [nioEventLoopGroup-3-20] - [com.xxx.socket.hander.SocketService - line:60]: 192.168.1.233:52124 移动客户端接入!
2023-08-30 14:28:59.760 - [INFO ] - [nioEventLoopGroup-3-20] - [com.xxx.socket.interceptor.EventListener - line:40]: 建立连接
2023-08-30 14:28:59.767 - [INFO ] - [nioEventLoopGroup-3-21] - [com.xxx.socket.hander.SocketService - line:68]: 192.168.1.233:52124 移动客户端已断开连接!
2023-08-30 14:28:59.767 - [INFO ] - [nioEventLoopGroup-3-21] - [com.xxx.socket.interceptor.EventListener - line:60]: 关闭连接。。。。。。。。。
2023-08-30 14:29:00.257 - [INFO ] - [nioEventLoopGroup-3-22] - [com.xxx.socket.hander.SocketService - line:60]: 192.168.1.233:52132 移动客户端接入!
2023-08-30 14:29:00.258 - [INFO ] - [nioEventLoopGroup-3-22] - [com.xxx.socket.interceptor.EventListener - line:40]: 建立连接
2023-08-30 14:29:00.263 - [INFO ] - [nioEventLoopGroup-3-23] - [com.xxx.socket.hander.SocketService - line:68]: 192.168.1.233:52132 移动客户端已断开连接!
2023-08-30 14:29:00.263 - [INFO ] - [nioEventLoopGroup-3-23] - [com.xxx.socket.interceptor.EventListener - line:60]: 关闭连接。。。。。。。。。
2023-08-30 14:29:00.534 - [ERROR] - [nioEventLoopGroup-3-24] - [c.c.socketio.transport.PollingTransport - line:168]: 1a348191-8b2a-42fc-b08e-552e5029507b is not registered. Closing connection
2023-08-30 14:29:00.538 - [ERROR] - [nioEventLoopGroup-3-25] - [c.c.socketio.transport.PollingTransport - line:147]: 1a348191-8b2a-42fc-b08e-552e5029507b is not registered. Closing connection
2023-08-30 14:29:00.742 - [ERROR] - [nioEventLoopGroup-3-26] - [c.c.socketio.transport.PollingTransport - line:168]: 7740ce73-8509-4233-a735-3c436a144d0e is not registered. Closing connection
2023-08-30 14:29:00.747 - [ERROR] - [nioEventLoopGroup-3-27] - [c.c.socketio.transport.PollingTransport - line:147]: 7740ce73-8509-4233-a735-3c436a144d0e is not registered. Closing connection
2023-08-30 14:29:02.047 - [INFO ] - [nioEventLoopGroup-3-28] - [com.xxx.socket.hander.SocketService - line:60]: 192.168.1.233:52156 移动客户端接入!
2023-08-30 14:29:02.047 - [INFO ] - [nioEventLoopGroup-3-28] - [com.xxx.socket.interceptor.EventListener - line:40]: 建立连接
2023-08-30 14:29:02.049 - [INFO ] - [nioEventLoopGroup-3-29] - [com.xxx.socket.hander.SocketService - line:60]: 192.168.1.233:52160 移动客户端接入!
2023-08-30 14:29:02.049 - [INFO ] - [nioEventLoopGroup-3-29] - [com.xxx.socket.interceptor.EventListener - line:40]: 建立连接

从日志上可以看到,断开重连频率非常高,每隔几十毫秒就会链接一次


六、原因

是nginx集群的负载均衡策略有问题,因为没有在test_socket集群指定策略,所以nginx默认使用的是轮询策略

那为什么轮询策略会导致socket不断重连呢?

是因为WebSocket协议握手的过程中不是一步而就的,它分了几个步骤,如果说上一次是与服务器1握手,下一次是与服务器2握手,那么肯定没法正常完成握手流程,连接也就没法正常建立了


七、解决

既然原因是因为socket链接没办法与固定的服务器进行通讯,那么只要解决这个问题就可以了

1、为socket集群指定负载均衡策略:ip_hash

## socket集群
upstream test_socket {# ip_hash:根据IP地址决定具体访问的服务器ip_hash;server 192.168.1.233:9901;server 192.168.1.243:9901;
}

2、重启nginx

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/81820.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Truenas Scale 安装 Official NextCloud

参考 Lawrence Systems 的 Youtube,频道有教程。 安装 安装 Collabora,只需要修改 账户,密码,及证书。 新增 dataset,名称 “NextCloud_Database”,其他默认新增 dataset,名称 “NextCloud_Data”&#…

什么是边缘计算网关?

边缘计算网关(简称 边缘网关)将云端功能扩展到本地的边缘设备,使边缘设备能够快速自主地响应本地事件,提供低延时、低成本、隐私安全、本地自治的本地计算服务。 同时所有服务都以 Docker 镜像方式安装,真正做到了跨平…

vue-grid-layout移动卡片到页面底部时页面滚动条跟随滚动

问题描述:默认情况下 vue-grid-layout 移动卡片到页面底部时页面滚动条并不会跟随卡片滚动。 问题解决: 在 grid-item中的move事件中,获取到当前移动的元素,并使用scrollIntoView方法来实现滚动条跟随。 代码如下: c…

安卓系列机型 另类体验第三方系统 DSU操作步骤解析 不影响主系统开启第二系统

dsu loader即 动态系统更新,可以在使用动态分区的安卓设备上,不影响原来系统的同时安装一个副系统,用于体验最新的原生安卓系统。可以不影响主系统的基础上体验其他gsi第三方。DSU 依赖于 Android 动态分区功能,并要求 GSI 作为可…

python爬虫爬取电影数据并做可视化

思路: 1、发送请求,解析html里面的数据 2、保存到csv文件 3、数据处理 4、数据可视化 需要用到的库: import requests,csv #请求库和保存库 import pandas as pd #读取csv文件以及操作数据 from lxml import etree #解析html库 from …

山西电力市场日前价格预测【2023-09-19】

日前价格预测 预测说明: 如上图所示,预测明日(2023-09-19)山西电力市场全天平均日前电价为358.08元/MWh。其中,最高日前电价为417.72元/MWh,预计出现在19: 00。最低日前电价为325.97元/MWh,预计…

十四、流式编程(2)

本章概要 中间操作 跟踪和调试流元素排序移除元素应用函数到元素在 map() 中组合流 中间操作 中间操作用于从一个流中获取对象,并将对象作为另一个流从后端输出,以连接到其他操作。 跟踪和调试 peek() 操作的目的是帮助调试。它允许你无修改地查看…

为何网站一定要使用SSL证书

当您在浏览器中输入网址并按下回车键时,您是否曾想过您的个人信息和隐私是否会被窃取?在当今数字化的时代,网络安全问题越来越受到人们的关注。而SSL证书正是保护您的网站和用户信息安全的重要工具。 SSL证书是一种数字证书,它使用…

Qt Quick 之 QML 与 C++ 混合编程详解

Qt Quick 之 QML 与 C 混合编程详解 一、Qt Quick 之 QML 与 C 混合编程详解在 QML 中使用 C 类和对象实现可以导出的 C 类Q_INVOKABLE 宏Q_ENUMSQ_PROPERTY注册一个 QML 中可用的类型注册 QML 类型在 QML 中导入 C 注册的类型完整的 colorMaker 实例导出一个 C 对象为 QML 的属…

【八大经典排序算法】冒泡排序

【八大经典排序算法】冒泡排序 一、概述二、思路解读三、代码实现四、优化 一、概述 冒泡排序由于其简单和易于理解,使其成为初学者学习排序算法的首选,也是初学者接触到的第一个排序算法。其原理是通过重复交换相邻的元素来将最大的元素逐步“冒泡”到…

二叉树的概念、存储及遍历

一、二叉树的概念 1、二叉树的定义 二叉树( binary tree)是 n 个结点的有限集合,该集合或为空集(空二叉树),或由一个根结点与两棵互不相交的,称为根结点的左子树、右子树的二叉树构成。 二叉树的…

C语言开发手册,辅助工具

方便查函数,头文件,日常语法,c99与c11的差异,等 https://www.php.cn/manual/view/34866.html

【JDK 8-函数式编程】4.6 方法引用与构造函数引用

一、 方法引用与构造函数引用 1. 说明 2. 语法: 二、静态方法 三、实例方法 四、构造函数 4.1 单个参数 4.2 2个参数 五、执行结果 一、 方法引用与构造函数引用 以前调用:对象.方法名、类名.方法名 jdk1.8提供了另外一种调用方式 :: 1. 说明 用来直接访…

分布式缓冲-搭建主从架构

个人名片: 博主:酒徒ᝰ. 个人简介:沉醉在酒中,借着一股酒劲,去拼搏一个未来。 本篇励志:三人行,必有我师焉。 本项目基于B站黑马程序员Java《SpringCloud微服务技术栈》,SpringCloud…

上海长宁来福士P2.5直径4米无边圆形屏圆饼屏圆面屏圆盘屏平面圆屏异形创意LED显示屏案例

长宁来福士广场是一个大型广场,坐落于上海中山公园商圈的核心区域,占地逾6万平方米,其中地上总建筑面积近24万平方米,总投资额约为96亿人民币。 LED圆形屏是根据现场和客户要求定制的一款异形创意LED显示屏,进行文字、…

WPF中DataGrid控件绑定数据源

步骤 创建数据源:首先,我们需要创建一个数据源,可以是一个集合(如List、ObservableCollection等),也可以是一个DataTable对象。数据源中的每个元素代表一行数据。 设置DataGrid的ItemsSource属性&#xff…

Linux集群时间同步方法

参考:https://www.cnblogs.com/felixzh/p/10638399.html

Dockerfile

Dockerfile Dockerfile就是一个文本文件,其中包含一个个的指令(Instruction),用指令来说明要执行什么操作来构建镜像。每一个指令都会形成一层Layer。 更新详细语法说明,请参考官网文档: Dockerfile reference | Docker Docs D…

JVM执行流程

一、Java为什么是一种跨平台的语言? 通常,我们编写的java源代码会被JDK的编译器编译成字节码文件,再由JVM将字节码文件翻译成计算机读的懂得机器码进行执行;因为不同平台使用的JVM不一样,所以不同的JVM会把相同的字节码…

以神龙出行小程序为例,说一些网站技术

注册和登录功能: 用户注册和登录可以使用手机号验证、第三方登录等方式来实现。这需要与后台服务器进行数据交互,并进行身份验证。 数据存储和管理: 用户的个人信息和常用地址需要进行存储和管理。这可以通过数据库来实现,如关系…