小牛队Firefox定期停止发布定时的socket.io事件

时间:2014-02-21 11:22:45

标签: javascript node.js firefox socket.io osx-mavericks

我有一个本地node.js服务器,它只是将socket.io事件记录到控制台。

在客户端,我使用setInterval()来设置每两秒钟发送到服务器的socket.io事件。

这是服务器端代码:

var handler = function(req, res) {
 fs.readFile('./page.html', function (err, data) {
   if(err) throw err;
   res.writeHead(200);
   res.end(data);
 });
}

// Include dependencies, set up the server and make it listen to the port.
var app = require('http').createServer(handler);
var io = require('socket.io').listen(app);
var fs = require('fs');
var port = 3250;
app.listen(port);

io.sockets.on('connection', function (socket) {
 socket.on("foo", function() {
   var now = new Date();
   console.log('got foo at ' + now.getSeconds());
 });
});

..和客户:

<!DOCTYPE html>
<html>
<head>
<title>Idle bug test</title>

<script src="/socket.io/socket.io.js"></script>

<script type="text/javascript">
window.onload = function() {
 socket = io.connect('http://localhost:3250');
 window.setInterval("socket.emit('foo');", 2000);
 //window.setInterval("socket.emit('foo');console.log(Date.now());", 2000);
}
</script>
</head><body></body>
</html>

重现错误:

  • 使用OS X Mavericks(Mountain Lion似乎不会发生)
  • 使用&#34; node index.js&#34;
  • 在终端中启动服务器
  • 启动Firefox(27.0.1)并转到localhost:3250
  • 不要打开Firefox控制台。
  • 专注于终端
  • 等待约一分钟,有时甚至更少,有时更多&#34;

结果:

$ node index.js
  info  - socket.io started
  debug - served static content /socket.io.js
  debug - client authorized
  info  - handshake authorized t9vjvs20j61l5gcuH52s
  debug - setting request GET /socket.io/1/websocket/t9vjvs20j61l5gcuH52s
  debug - set heartbeat interval for client t9vjvs20j61l5gcuH52s
  debug - client authorized for
  debug - websocket writing 1::
got foo at 34
got foo at 36
got foo at 38
got foo at 40
got foo at 42
got foo at 44
got foo at 46
got foo at 48
got foo at 50
got foo at 52
got foo at 54
got foo at 56
  debug - emitting heartbeat for client t9vjvs20j61l5gcuH52s
  debug - websocket writing 2::
  debug - set heartbeat timeout for client t9vjvs20j61l5gcuH52s
  debug - got heartbeat packet
  debug - cleared heartbeat timeout for client t9vjvs20j61l5gcuH52s
  debug - set heartbeat interval for client t9vjvs20j61l5gcuH52s
got foo at 58
got foo at 0
got foo at 2
got foo at 4
got foo at 6
got foo at 8
got foo at 10
got foo at 22 # WTF?
got foo at 22
  debug - emitting heartbeat for client t9vjvs20j61l5gcuH52s
  debug - websocket writing 2::
  debug - set heartbeat timeout for client t9vjvs20j61l5gcuH52s
  debug - got heartbeat packet
  debug - cleared heartbeat timeout for client t9vjvs20j61l5gcuH52s
  debug - set heartbeat interval for client t9vjvs20j61l5gcuH52s
got foo at 33
got foo at 33
got foo at 45
got foo at 45
  debug - emitting heartbeat for client t9vjvs20j61l5gcuH52s
  debug - websocket writing 2::
  debug - set heartbeat timeout for client t9vjvs20j61l5gcuH52s
  debug - got heartbeat packet
  debug - cleared heartbeat timeout for client t9vjvs20j61l5gcuH52s
  debug - set heartbeat interval for client t9vjvs20j61l5gcuH52s
got foo at 47
got foo at 59
got foo at 59
got foo at 1 # Brought focus back on Firefox, things back to normal
  debug - client authorized
  info  - handshake authorized aqvmz-zNImkzF0zPH52t
  debug - setting request GET /socket.io/1/websocket/aqvmz-zNImkzF0zPH52t
  debug - set heartbeat interval for client aqvmz-zNImkzF0zPH52t
  debug - client authorized for
  debug - websocket writing 1::
got foo at 3
got foo at 5
got foo at 7
got foo at 9
got foo at 11
  debug - emitting heartbeat for client t9vjvs20j61l5gcuH52s
  debug - websocket writing 2::
  debug - set heartbeat timeout for client t9vjvs20j61l5gcuH52s
  debug - got heartbeat packet
  debug - cleared heartbeat timeout for client t9vjvs20j61l5gcuH52s
  debug - set heartbeat interval for client t9vjvs20j61l5gcuH52s
got foo at 13
got foo at 15
got foo at 17
^C$

在标有&#34; WTF&#34;的点上,Firefox开始休息,并以双倍方式发出事件。

重现不同的错误:

  • 除了发出事件外,还切换到使用记录到控制台的客户端代码行。
  • 使用OS X Mavericks(Mountain Lion似乎不会发生)
  • 在终端&#34;节点index.js&#34;
  • 中启动服务器
  • 启动Firefox(27.0.1)并转到localhost:3250
  • 打开Firefox控制台。
  • 专注于终端
  • 等待&#34;超过一分钟的事情&#34;

结果:Firefox在发送socket.io事件时发疯,同时在控制台打开的情况下登录浏览器控制台。或者服务器开始查看未发送的事件。在Firefox的控制台中,每2秒只发生一次事件。

$ node index.js
  info  - socket.io started
  debug - served static content /socket.io.js
  debug - client authorized
  info  - handshake authorized iBFAUZOa7BHwJYYtNNLA
  debug - setting request GET /socket.io/1/websocket/iBFAUZOa7BHwJYYtNNLA
  debug - set heartbeat interval for client iBFAUZOa7BHwJYYtNNLA
  debug - client authorized for
  debug - websocket writing 1::
got foo at 42
got foo at 44
got foo at 46
got foo at 48
got foo at 50
got foo at 52
got foo at 54
got foo at 56
got foo at 58
got foo at 0
got foo at 2
got foo at 4
  debug - emitting heartbeat for client iBFAUZOa7BHwJYYtNNLA
  debug - websocket writing 2::
  debug - set heartbeat timeout for client iBFAUZOa7BHwJYYtNNLA
  debug - got heartbeat packet
  debug - cleared heartbeat timeout for client iBFAUZOa7BHwJYYtNNLA
  debug - set heartbeat interval for client iBFAUZOa7BHwJYYtNNLA
got foo at 6
got foo at 8
got foo at 10
got foo at 12
got foo at 14
got foo at 16
got foo at 18
got foo at 20
got foo at 22
got foo at 24
got foo at 26
got foo at 28
got foo at 30
  debug - emitting heartbeat for client iBFAUZOa7BHwJYYtNNLA
  debug - websocket writing 2::
  debug - set heartbeat timeout for client iBFAUZOa7BHwJYYtNNLA
  debug - got heartbeat packet
  debug - cleared heartbeat timeout for client iBFAUZOa7BHwJYYtNNLA
  debug - set heartbeat interval for client iBFAUZOa7BHwJYYtNNLA
got foo at 32
got foo at 34
got foo at 36
got foo at 38
got foo at 40
got foo at 42
got foo at 44
got foo at 46
got foo at 48
got foo at 50
got foo at 52
got foo at 54
  debug - emitting heartbeat for client iBFAUZOa7BHwJYYtNNLA
  debug - websocket writing 2::
  debug - set heartbeat timeout for client iBFAUZOa7BHwJYYtNNLA
  debug - got heartbeat packet
  debug - cleared heartbeat timeout for client iBFAUZOa7BHwJYYtNNLA
  debug - set heartbeat interval for client iBFAUZOa7BHwJYYtNNLA
got foo at 56
got foo at 58
got foo at 0
got foo at 2
got foo at 4
got foo at 6
got foo at 8
got foo at 10
got foo at 12
got foo at 14
got foo at 16
got foo at 18
got foo at 20
  debug - emitting heartbeat for client iBFAUZOa7BHwJYYtNNLA
  debug - websocket writing 2::
  debug - set heartbeat timeout for client iBFAUZOa7BHwJYYtNNLA
  debug - got heartbeat packet
  debug - cleared heartbeat timeout for client iBFAUZOa7BHwJYYtNNLA
  debug - set heartbeat interval for client iBFAUZOa7BHwJYYtNNLA
  debug - client authorized
  info  - handshake authorized RjQh8QPYaxxxJbiONNLB
  debug - setting request GET /socket.io/1/websocket/RjQh8QPYaxxxJbiONNLB
  debug - set heartbeat interval for client RjQh8QPYaxxxJbiONNLB
  debug - client authorized for
  debug - websocket writing 1::
got foo at 20
# WTF? Snipped 126 lines of "got foo at 20"
got foo at 20
got foo at 21
got foo at 21
# WTF? Snipped 124 lines of "got foo at 21"
# Focused on Firefox
got foo at 21
got foo at 22
got foo at 22
got foo at 24
got foo at 24
got foo at 26
got foo at 26
got foo at 28
got foo at 28
got foo at 30
got foo at 30
got foo at 32
got foo at 32
got foo at 34
got foo at 34
got foo at 36
got foo at 36
got foo at 38
got foo at 38
^C$

任何可能导致此问题的想法?

0 个答案:

没有答案