如何解决 Safari 10.1 错误 "Failed to send WebSocket frame"?
How to work around Safari 10.1 error "Failed to send WebSocket frame"?
Safari 10.1 中的 WebSocket API 似乎有最大数量的二进制数据可以缓冲,然后发送的下一条消息出现错误 "WebSocket connection to ... failed: Failed to send WebSocket frame."
Safari 然后关闭与代码 1006 (CLOSE_ABNORMAL) 的连接。
WebSockets 是 supposed to report the bufferedAmount
- 但 Safari 总是报告 0
直到 错误发生后连接关闭。
我尝试在每条消息之间设置 100 毫秒的 setTimeout,这似乎适用于小块数据的情况,但它似乎很脆弱,大块在我发送结束时仍然会出错 JSON消息,即使有更长的延迟。
你可以see the bug in action here - the "Play Sample" buttons work in Safari 10.03 but error in 10.1. (Code that handles the WebSocket connection.)
关于如何解决这个问题有什么想法吗?或者限制甚至是多少?我知道 Safari 是开源的,但我不确定去哪里找。
更新:这是一个更简单的例子:
// this fails in Safari 10.1 but works in 10.03 (and other browsers)
var ws = new WebSocket('wss://echo.websocket.org');
ws.onerror = function(evt) {
// Not sure why, but error events seem to have no useful information
// The console, however, will have the following error:
// WebSocket connection to 'wss://echo.websocket.org/' failed: Failed to send WebSocket frame.
console.log("WebSocket error - see console for message");
}
ws.onclose = function(evt) {
console.log(`WebSocket closed with code: ${evt.code}, reason: ${evt.reason}`);
}
ws.onopen = function() {
console.log('sending first binary message');
ws.send(new Uint8Array(23085));
console.log('bufferedAmount is ' + ws.bufferedAmount);
// this gets the error
console.log('sending second binary message');
ws.send(new Uint8Array(23085));
console.log('bufferedAmount is ' + ws.bufferedAmount);
console.log('sending third binary message');
ws.send(new Uint8Array(23085));
console.log('bufferedAmount is ' + ws.bufferedAmount);
ws.close();
}
https://jsfiddle.net/yta2mjuf/2/
第二条消息获取错误关闭连接,第三条消息后,bufferedAmount
为23093。
我在 Safari 10.1.2 上尝试了您的真实世界 link,但没有发现问题。好像已经修复了。
Safari 10.1 中的 WebSocket API 似乎有最大数量的二进制数据可以缓冲,然后发送的下一条消息出现错误 "WebSocket connection to ... failed: Failed to send WebSocket frame."
Safari 然后关闭与代码 1006 (CLOSE_ABNORMAL) 的连接。
WebSockets 是 supposed to report the bufferedAmount
- 但 Safari 总是报告 0
直到 错误发生后连接关闭。
我尝试在每条消息之间设置 100 毫秒的 setTimeout,这似乎适用于小块数据的情况,但它似乎很脆弱,大块在我发送结束时仍然会出错 JSON消息,即使有更长的延迟。
你可以see the bug in action here - the "Play Sample" buttons work in Safari 10.03 but error in 10.1. (Code that handles the WebSocket connection.)
关于如何解决这个问题有什么想法吗?或者限制甚至是多少?我知道 Safari 是开源的,但我不确定去哪里找。
更新:这是一个更简单的例子:
// this fails in Safari 10.1 but works in 10.03 (and other browsers)
var ws = new WebSocket('wss://echo.websocket.org');
ws.onerror = function(evt) {
// Not sure why, but error events seem to have no useful information
// The console, however, will have the following error:
// WebSocket connection to 'wss://echo.websocket.org/' failed: Failed to send WebSocket frame.
console.log("WebSocket error - see console for message");
}
ws.onclose = function(evt) {
console.log(`WebSocket closed with code: ${evt.code}, reason: ${evt.reason}`);
}
ws.onopen = function() {
console.log('sending first binary message');
ws.send(new Uint8Array(23085));
console.log('bufferedAmount is ' + ws.bufferedAmount);
// this gets the error
console.log('sending second binary message');
ws.send(new Uint8Array(23085));
console.log('bufferedAmount is ' + ws.bufferedAmount);
console.log('sending third binary message');
ws.send(new Uint8Array(23085));
console.log('bufferedAmount is ' + ws.bufferedAmount);
ws.close();
}
https://jsfiddle.net/yta2mjuf/2/
第二条消息获取错误关闭连接,第三条消息后,bufferedAmount
为23093。
我在 Safari 10.1.2 上尝试了您的真实世界 link,但没有发现问题。好像已经修复了。