空闲时间过后,Edge浏览器的Websocket连接将自动关闭 [英] Edge browser Websocket connection will be automatically closed after an idle time

查看:462
本文介绍了空闲时间过后,Edge浏览器的Websocket连接将自动关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在新的Window Edge浏览器上进行了有关Websocket的测试.

I did a test about Websocket on new Window Edge browser.

似乎在空闲时间(没有数据传输的2个端点)之后,Edge浏览器上的websocket连接将自动关闭. 在Chrome或Firefox上不会发生此问题.

It seems that the websocket connection on the Edge browser will be automatically closed after an idle time (no data transmission b/w 2 endpoints). The issue does not happens on chrome or firefox.

我只是想知道: 在Edge浏览器上初始化websocket连接以保持连接打开时,是否还有其他配置?

I just wonder: Is there any additional configuration when initializing the websocket connection on Edge browser to keep the connection opened?

我真的不希望实现心跳机制,因为实际上所有内容在其他浏览器上仍然可以正常运行.

I really dont' want to implement heartbeat mechanism because actually everything still works well on other browsers.

推荐答案

这可能不是您想要的答案,但是...

This might not be the answer you want, but...

大多数用于websocket应用程序的生产环境都在Websocket代理(Apache,Nginx等)后面运行,该Websocket代理通常还充当负载平衡器.

Most production environments for websocket apps run behind a Websocket Proxy (Apache, Nginx etc') that usually also acts as a load balancer.

这些服务器还将实现避免half closed套接字所需的超时"机制(当仅一侧关闭连接并且没有数据传输时,不会引发任何错误并且可以无限期地打开文件句柄)

These servers will also implement a 'timeout' mechanism that is needed to avoid half closed sockets (when only one side closed the connection and no data is transmitted, no error is raised and the file handle can be left open indefinitely).

例如, Heroku强制执行55秒的超时窗口.

这意味着您可能仍然应该设置心跳信号-即使您的开发应用程序没有遇到关机问题.

This means you should probably set up a heartbeat anyway - even if your development app doesn't experience shutdowns.

如果您正在编写服务器端应用程序并可以控制websocket,则可能应设置不会导致引发onmessage事件的ping帧(ping和pong帧具有不同的,并且不属于常规消息序列.

If you're writing a server-side app and have control over the websocket, you should probably set up ping frames that won't cause an onmessage event to be raised (ping and pong frames have a different op code and aren't part of the regular message sequence).

某些websocket框架(例如Ruby上的Plezi)将自动设置ping作为默认选项,但是某些服务器/框架则由您自己决定.

Some websocket frameworks (such as Plezi on Ruby) will set up pinging automatically as a default option, but some servers / frameworks leave this up to you.

总结:

这些断开连接将是生产环境预期行为(甚至是必需的行为).尽管这也很可能是MS Edge的问题,但在两种情况下您都可能必须实施检测信号.

These disconnections WILL be the expected behavior (even a required behavior) for a production environment. Although it's also very likely to be an MS Edge issue, you will probably have to implement a heartbeat in both cases.

PS

Websocket标准规定:

The Websocket standard states that:

服务器可以在需要时关闭WebSocket连接.客户端不应随意关闭WebSocket连接.

Servers MAY close the WebSocket connection whenever desired. Clients SHOULD NOT close the WebSocket connection arbitrarily.

服务器(以及Websocket代理和负载平衡器)使用它来建立其超时时间. 重新连接是客户的责任.

Servers (and Websocket Proxies and load balancers) use this to establish their timeouts. It's the client's responsibility to reconnect.

MS Edge确实不应该利用超时,因为按照标准,这不是预期的行为...尽管Edge可能会这样做以确保连接仍处于打开状态(通过强制脚本重新连接为对服务器任意断开的反应).

MS Edge really shouldn't utilize a timeout, as this isn't the expected behavior according to the standard... although Edge might be doing it to make sure the connection is still open (by forcing the script to reconnect as a reaction to a server's arbitrary disconnection).

这篇关于空闲时间过后,Edge浏览器的Websocket连接将自动关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆