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

news2024/11/22 11:35:34

一、场景

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.io
	location ~* /socket.io/* {
		proxy_pass http://test_socket;
		
		# WebScoket Support
		proxy_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.coloradmin.cn/o/1006484.html

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

相关文章

51单片机智能小车—PWM方式实现小车调速和转向

目录 1. 让小车动起来 2. 串口控制小车方向 3. 如何进行小车PWM调速 4. PWM方式实现小车转向 1. 让小车动起来 电机模块开发 L9110s概述 接通VCC,GND 模块电源指示灯亮, 以下资料来源官方,具体根据实际调试 IA1输入高电平&#xff0c…

小红书《乡村振兴战略下传统村落文化旅游设计》中南大博士许少辉八一新著

小红书《乡村振兴战略下传统村落文化旅游设计》中南大博士许少辉八一新著

使用伏格尔法解决运输问题

物流和供应链管理是当前管理研究的热点和前沿领域。供应链是一个由物流系统和该供应链中的所有单个组织或企业相关活动组成的网络。为满足供应链中顾客需求,需要对商品服务及相关信息,从产地到消费地高效率低成本地流动及储存进行规划、执行和控制。运筹…

基础秘钥、公钥、地址的熟悉指南

1. 地址 0基础漫画式阅读:https://www.cnblogs.com/charlesblc/p/6130433.html 清晰详细的地址生成解释:比特币:账户私钥、公钥、地址的生成 - kumata - 博客园 (cnblogs.com) 对原理更详细解释:区块链技术核心篇之二&#xff…

计算机竞赛 大数据房价预测分析与可视

0 前言 🔥 优质竞赛项目系列,今天要分享的是 🚩 大数据房价预测分析与可视 🥇学长这里给一个题目综合评分(每项满分5分) 难度系数:3分工作量:3分创新点:4分 该项目较为新颖,适合…

java复习-线程常用操作方法

线程常用操作方法 线程的主要方法都定义在 Thread类 之中,因此此处就是学习Thread中的方法。 一. 线程的命名与取得 构造方法:public Thread(Runnable target, String name)设置名字:public final synchronized void setName(String name)…

解决“您在 /var/spool/mail/root 中有新邮件”问题

一、发现问题 二、解决问题 1、删除邮件 cat /dev/null > /var/spool/mail/root 2、禁止系统启动邮件检查 echo "unset MAILCHECK" >> /etc/profile 三、解决结果

16G FC SFP+ SW光模块应用解析

随着云计算、大数据和物联网等技术的迅猛发展,数据传输速率不断提高。传统的铜缆传输面临带宽瓶颈和信号衰减等问题,而光纤传输凭借其高带宽、低损耗等优势成为了现代通信的主要选择。易天光通信的16G SFP SW 多模光模块作为高性能光纤传输设备&#xff…

SAP HANA 体系结构,LandScape,规模调整:完整教程

目录 一、SAP HANA 体系结构 二、SAP HANA 景观 三、SAP HANA 大小调整 SAP HANA 数据库是以主内存为中心的数据管理平台。 SAP HANA 数据库在 SUSE Linux Enterprises Server 上运行,并基于 C 语言构建。 SAP HANA 数据库可以分发到多台计算机。 SAP HANA 的优…

上海亚商投顾:三大指数小幅下跌 光刻机概念股午后走强

上海亚商投顾前言:无惧大盘涨跌,解密龙虎榜资金,跟踪一线游资和机构资金动向,识别短期热点和强势个股。 一.市场情绪 三大指数昨日小幅调整,创业板指走势较弱。减肥药概念股继续大涨,常山药业2连板&#x…

CDH 集群离线部署、大数据组件安装与扩容详细步骤(cdh-6.3.1)

一、环境准备 1、服务器配置和角色规划 IP 地址主机名硬件配置操作系统安装步骤10.168.168.1cm-server8C16GCentos7新建10.168.168.2agent018C16GCentos7新建10.168.168.3agent028C16GCentos7新建10.168.168.4agent038C16GCentos7新建10.168.168.5agent048C16GCentos7扩容 2…

Harmonic Drive哈默纳科减速机旋转方向和减速比

Harmonic Drive哈默纳科减速机是一款广泛应用于工业生产中的机械设备,通过减速旋转运动来降低机器的转速和输出功率,从而实现精准的调节和控制。哈默纳科减速机的结构紧凑,体积小,重量轻,安装方便,维护简单…

深入了解 FastAPI 鉴权:掌握前后端身份验证的最佳实践

在构建现代化的 Web 应用程序时,用户身份验证和授权是不可或缺的组成部分。FastAPI 提供了多种方法来实现鉴权,以确保只有授权用户可以访问特定的资源或执行特定的操作。本文将介绍 FastAPI 中的鉴权方法,包括基本概念、实践案例和一些提示和…

企业如何转动自己的命运齿轮,实现数字化转型

企业进行数字化转型,需要熟悉数字化转型相关知识,了解众多前辈企业数字化转型成功或失败的案例,从中提炼出数字化转型的关键要点,在数字化转型的浪潮中,破浪前行。 数字化转型关键因素 1、数据 数据是数字化转型的基…

zeppelin安装python(使用pymysql包)

zeppelin安装python: zeppelin的测试环境安装的python的pymysql包 更改zeppelin的python的interpreters(注意需要匹配跟我们的python版本相匹配) 参考官网链接:https://zeppelin.apache.org/docs/0.10.1/interpreter/python.htm…

开源软件镜像平台-山东大学镜像站

山东大学镜像站 山东大学镜像站是由山东大学(青岛)网管会镜像站学生运营团队运营的开源镜像站平台,网站平台专门为技术爱好者、工程师、科研人员等开源爱好者提供给丰富的开源镜软件像资源,以及相关的学习和帮助资料,…

简单聊聊G1垃圾回收算法整个流程 --- 理论篇 -- 上

简单聊聊G1垃圾回收算法整个流程 --- 理论篇 -- 上 G1 是什么为什么需要 G1 G1 GC 流程并发标记根对象枚举安全点 位图标记整体流程初始标记阶段并发标记阶段三色标记法SATB(原始快照)SATB 专用写屏障优化SATB 专用写屏障和多线程执行 最终标记存活对象计数收尾工作转移效率总结…

Python实现自主售卖机

1 问题 在python中我们常常使用到条件判断,if语句时常见的条件判断语句之一。那么如何使用if语句实现根据情况自动选择商品进行售卖呢? 2 方法 根据if语句执行时从上往下执行的特点,使用if语句、dict和list来实现整个流程。 代码清单 1 drink…

jd(按关键字搜索商品)API接口

为了进行电商平台 的API开发,首先我们需要做下面几件事情。 1)开发者注册一个账号 2)然后为每个jd应用注册一个应用程序键(App Key) 。 3)下载jdAPI的SDK并掌握基本的API基础知识和调用 4)利用SDK接口和…

长胜证券:新股配号是怎么配的?

近年来,股票买卖成为了越来越多人的出资选择,而新股的配号过程也成为了社会热议的论题。那么,新股配号是怎么配的呢?本文将从发行方法、配号规矩和影响要素等多个角度分析,为读者解答这一问题。 发行方法 首先要了解的…