我正在使用Node JS + socket.io应用程序。
整个应用程序运行正常,但是大约5分钟后服务器停止接收客户端触发的事件。 :(
当未触发事件时,我可以看到服务器已成功接收到心跳。
debug - got heartbeat packet
debug - cleared heartbeat timeout for client 4cKMC4Iqje-7dDfibJZm
debug - set heartbeat interval for client 4cKMC4Iqje-7dDfibJZm
debug - emitting heartbeat for client 4cKMC4Iqje-7dDfibJZm
debug - websocket writing 2::
debug - set heartbeat timeout for client 4cKMC4Iqje-7dDfibJZm
我也确定客户端正在发出消息,因为我可以看到在chrome Developer工具中发送的数据。 以下是正在发送的样本数据
5:::{"name":"ev_SendChatMessage","args":[{"chatMsg":"dgdfsgfs","aID":"10010001835364"}]}
另外,我已经在服务器机器上检查了TCP Dump的结果,它已成功接收数据包。
节点版本为v0.10.21
socket.io版本为0.9.16
客户代码
var socket;
$(function()
{
// Connect to the Live Proctoring Server.
socket = io.connect('http://autoproc.am.in:8899');
});
function SendChatMsg()
{
// This get called on click of a button
socket.emit( "ev_SendChatMessage", { chatMsg : "textToSend", aID : "123" } );
}
服务器代码
var options = {};
var io = require( 'socket.io' ).listen( 8899, options );
// Called when a connection is made with a new Client
function OnConnection ( socket )
{
console.log( "Connection has been made with " + socket.id );
socket.on('ev_SendChatMessage', SendChatMessageFromModerator );
socket.on('disconnect', OnDisconnect );
}
// This stops getting called after some time. In the beginning it is getting called successfully.
function SendChatMessageFromModerator( data )
{
console.log( data );
}
编辑:更准确地说,只有在收到7-8条消息并发出7-8条消息后才会发生这种情况。
编辑:我试图将传输机制从Web Socket更改为“xhr-polling”。即便如此,我也面临同样的问题,而不是我可以在调试中看到一些值得的东西。
debug - xhr-polling received data packet 5:::{"name":"ev_SendChatMessage","args":[{"chatMsg":"sfsdfdsfs","aID":"10010001167896"}]}
debug - clearing poll timeout
debug - xhr-polling writing 8::
debug - set close timeout for client JfaWyiP3YqTRmqyzz4z6
debug - xhr-polling closed due to exceeded duration
debug - setting request GET /socket.io/1/xhr-polling/JfaWyiP3YqTRmqyzz4z6?t=1389965419417
debug - setting poll timeout
debug - discarding transport
debug - cleared close timeout for client JfaWyiP3YqTRmqyzz4z6
这清楚地表明数据已经到达Node JS应用程序。
答案 0 :(得分:0)
我找到了解决问题的方法..
问题是我正在创建数据库连接池,但我没有使用dbConn.release();
发布连接
一旦池中的连接耗尽,应用程序就会一直等待从池中提取数据库连接。
简而言之,魔鬼在细节中。我在问题中没有提到的细节。哈哈哈.. !!