不可能增加缓冲区宽度以避免帧丢失
或
无法正确管理WS碎片
摘要
我的目标:
一个非常简单的事情:有websocket隧道传输至少2/3MB的数据每个隧道。我需要发送目录结构,因此数据可以非常多。
问题:
从A发送到B的超过17 to的WebSocket消息会导致“通信丢失”或数据包丢失/丢失;连接/隧道仍然无法在同一隧道(从A到B)上发送新消息;相反,从B到A继续工作。
我必须重新启动隧道才能恢复功能。
这也可能是一个想法,即当达到阈值时重新启动隧道的数据包堆的管理,但是很明显,我需要一次发送超过阈值的内容。
“信号路径”:
GoLang app(Client) ---> :443 NGINX Proxy(Debian) ---> :8050 NodeJS WS Server
测试:
发送每条1000字节的X消息/块的
分析:
eth
lo
ws.on('message', (msg)=>{console.log(msg)})
。
代码& Config:
GoLang应用相关部分
websocket.DefaultDialer = &websocket.Dialer{ Proxy: http.ProxyFromEnvironment, HandshakeTimeout: 45 * time.Second, WriteBufferSize: 1000, //also tried with 2000, 5000, 10000, 11000 c, _, err := websocket.DefaultDialer.Dial(u.String(), nil) wsConn = c bufferChunk := 1000 bufferSample := "" for j := 7; j <= bufferChunk; j++ { bufferSample = bufferSample + "0" i := 1 for { sendingBytes := i * bufferChunk fmt.Println(strconv.Itoa(sendingBytes) + " bytes sent") wsConn.WriteMessage(websocket.TextMessage, []byte(bufferSample)) time.Sleep(1000 * time.Millisecond) }
NGINX conf:
upstream backend { server 127.0.0.1:8050; server { server_name my.domain.com; large_client_header_buffers 8 32k; location / { 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; proxy_buffers 8 2m; proxy_buffer_size 10m; proxy_busy_buffers_size 10m; proxy_pass http://backend; proxy_redirect off; #proxy_buffering off; ### ON/OFF IT'S THE SAME # enables WS support proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; ### "upgrade" it's the same listen 443 ssl; # managed by Certbot ssl_certificate /etc/letsencrypt/live/my.domain.com/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/my.domain.com/privkey.pem; # managed by Certbot include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot server { if ($host = my.domain.com) { return 301 https://$host$request_uri; } # managed by Certbot server_name my.domain.com; listen 80; return 404; # managed by Certbot }
NodeJS代码:
//index.js const config = require("./config.js"); const fastify = require('fastify')(); const WsController = require("./controller"); fastify.register(require('fastify-websocket'), { /*these options are the same as the native nodeJS WS*/ options :{ maxPayload: 10 * 1024 * 1024, maxReceivedFrameSize: 131072, maxReceivedMessageSize: 10 * 1024 * 1024, autoAcceptConnections: false fastify.ready(err => { if (err) throw err console.log("Server started") fastify.websocketServer .on("connection", WsController) //controller.js