Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
164 views
in Technique[技术] by (71.8m points)

javascript - WebSockets not closing on IE if closing handshake is never made

I've been implementing a WebSocket with JavaScript and I have this one problem:
The endpoint that my web-application is connected to doesn't send back a close control frame when I'm sending it one.

This isn't that bad because browsers close the WebSocket connection after a while.

But a few things to notice are:

  • Browsers do only allow a specific amount of WebSockets to be connected at the same time.

  • When refreshing the web-application a new WebSocket is created

This causes the problem on IE:
When refreshing the web-application more than 6 times, a WebSocket connection cannot be made.

It seems like IE doesn't "delete" the WebSockets if they haven't been closed cleanly. And what's odd is that the amount of web sockets never seems to decrease by refreshing or just by waiting.

Only by closing the browser window, or the tab resets the number of WebSockets to 0.


I've done some researching and this is what I've found out:


Browsers do only support a specific amount of WebSockets to be connected at the same time.

IE supports 6 websockets to be connected [link]

Chrome supports 255 websockets to be connected [link].

And socket.onclose() isn't triggered when you do socket.close(), it is called when the endpoint responses with a close message. [link]

IE waits 15 seconds for the endpoint to send the close message [link].

Chrome waits for 60s for the responding message [Sorry, no link for this, found this out by testing].

If no response message is received, the browser closes the WebSocket connection and a TimeoutError should occur.

Please correct me if I'm wrong :)


I've tried to use unbeforeload to disconnect from the endpoint in hope that the browser would close the connection after a while, but with no luck. [link].
It can also be the cause of that IE aren't able to do request inside the unbeforeload function [link].

Question:

  1. Is there any way to reset the number of WebSockets that are connected in the browser to the endpoint with JavaScript?
  2. Is there a way to disconnect a WebSocket from the endpoint immediately without closing the connection cleanly?
  3. Is the only way to get this to work to inform the ones who host their endpoint make some changes so they do send a closing frame back?
  4. Is there anything I've misunderstood or that I could try to get this to work?

Here is (in my opinion) good documentation about the WebSocket protocols if somebody would like to read more about it [link1] [link2].

UPDATE:

Only by refreshing the web-application on IE the WebSockets don't get destroyed.
If you navigate between pages in the web-application a new WebSocket will be made but the last WebSocket will get destroyed.

question from:https://stackoverflow.com/questions/51893524/websockets-not-closing-on-ie-if-closing-handshake-is-never-made

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If it is just an edge case problem, then using a http fallback might be your only option. I guess you already do this for proxy servers that block socket connection away.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...