Node server stops responding after certain period

3,655 views
Skip to first unread message

tamizh arasan

unread,
Jul 15, 2014, 3:50:43 AM7/15/14
to nod...@googlegroups.com
I am using node server for my mobile based web application. it stops responding after a certain time from starts working. but when i restart the server it works fine and again goes not responding state after certain period. I am continuously restarting my server every day to run my application. i don't what is the issue with it. My server is not connected more than 30 connection. It is in testing phase. and as well it didn't deal with big data transfer. i have used below api s for my application.

var app = require('http').createServer(),                 //  Creating http server instance
io = require('socket.io').listen(app),         // Creating Socket.io instance
fs = require('fs'), //
http = require('http'), // Creating http instance
gm = require('googlemaps'), // Creating instance for nodejs googlemaps
mysql = require('mysql'), // Creating instance for mysql
API = require ('wechat').API, // Creating WeChat NodeJs Instance
connectionsArray = [], // Creating Connections Array instance
connection = mysql.createConnection({ // Creating Mysql Connection instance
host: '127.0.0.1',
user: 'test',
password: ''
database: 'test',
port: 3306
}); 
 
I am new to Node.js. Can anybody tell me how to resolve it. 

Daniel Alberto Martinez

unread,
Jul 15, 2014, 3:46:11 PM7/15/14
to nod...@googlegroups.com
Exists many ways in which your server can be down. Most common are uncaught exceptions.
Any way, you can use forever:
"A simple CLI tool for ensuring that a given node script runs continuously"

tamizh arasan

unread,
Jul 17, 2014, 5:06:22 AM7/17/14
to nod...@googlegroups.com
Now only i have found some changes in my application after it stops responding.In my Application the server accepts response from the application via socket.on like below
socket.on('check_open_id',function(data){
console.log("New message from application" + data);
data.socket_session_id = socket.id;
console.log("New message from Application Socket Session Id" + data.socket_session_id);
//Function to check the registration details
checkRegisterationDetails(data);
});
and it respond with showing output in console. and it run the function in it. in that function 
var checkRegisterationDetails= function(data){
    console.log("Testing Registered");
console.log(data);

var query = connection.query('select * from test where open_id = "'+data.openid+'"');
result=[];
query
    .on('error', function(err) {
// Handle error, and 'end' event will be emitted after this as well
console.log(err);
//updateSockets(err);
    })
    .on('result', function(user) {
// it fills our array looping on each user row inside the db
result.push(user);
//console.log("openid"+result);
    })
    .on('end', function() {
console.log(result.length);
                io.sockets.socket(data.socket_session_id).emit('check_registration_status', {message:"your registration already completes and no engaged booking",details :                             details[0]});
   })
}
here also it give output in the console window but the queries are not executed and as well the socket.emit also not executed. can any body tell how to over come this problem. these problem arises after certain period from server starts. when it restarts it works fine untill some period.

tamizh arasan

unread,
Jul 19, 2014, 8:44:27 AM7/19/14
to nod...@googlegroups.com
Now i have founded that sql connection goes to sleep condition when there is no request for longer time(i.e 12hours). so can anybody suggest me how to over come this problem. Thanks in advance.

mscdex

unread,
Jul 19, 2014, 2:48:23 PM7/19/14
to nod...@googlegroups.com
On Saturday, July 19, 2014 8:44:27 AM UTC-4, tamizh arasan wrote:
Now i have founded that sql connection goes to sleep condition when there is no request for longer time(i.e 12hours). so can anybody suggest me how to over come this problem. Thanks in advance.

What I have done (when using mysql2[1]) is set up a timer that periodically calls `connection.ping();` to help make sure the connection stays alive.

[1] https://github.com/sidorares/node-mysql2

Hernán Tierno

unread,
Jul 19, 2014, 10:20:04 PM7/19/14
to nod...@googlegroups.com
Are you behind a firewall? Some firewalls close the tcp connection (only on one side of the connection). I solved this kind of trouble turning on the tcp keep alive on the db side. 


On Saturday, July 19, 2014, tamizh arasan <tamizha...@gmail.com> wrote:
Now i have founded that sql connection goes to sleep condition when there is no request for longer time(i.e 12hours). so can anybody suggest me how to over come this problem. Thanks in advance.

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/ee5505b5-96cf-454d-9736-fcd6e07db09e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
----------------------------
Hernán Tierno
hti...@gmail.com
Reply all
Reply to author
Forward
0 new messages