Wednesday, 26 April 2017

Node.js - events.js throw er

Before posting this question I went through a couple of SO posts with the same heading. All of them suggested me to restart my app..I tried that but I am still getting the error.

The code that is throwing the error is

app.post('/insert', function(request, response) {
    var connection = mySequel.createConnection(ConnectionParams);
    connection.connect();
    var UserName = request.body.UserName;
    //     insert into userrecords values ("123456",DEFAULT,DEFAULT,DEFAULT,10);
    var InsertQuery = "insert into userrecords values (" + UserName + ",DEFAULT,DEFAULT,DEFAULT,-10);";
    connection.query(InsertQuery, function(error, result, fields) {
        if (error) {
            response.send("error");
            console.log(error);
            throw error;
        } else {
            // response.send("success");
            console.log(result.insertId);
            response.send(result.insertId);
        }
    });
    connection.end();
});

The error caused by the code is this

events.js:160
2017-04-26T11:42:52.410094+00:00 app[web.1]: 
2017-04-26T11:42:52.410092+00:00 app[web.1]:       throw er; // Unhandled 'error' event
2017-04-26T11:42:52.410096+00:00 app[web.1]: Error: Quit inactivity timeout
2017-04-26T11:42:52.410097+00:00 app[web.1]:     at Quit.<anonymous> (/app/node_modules/mysql/lib/protocol/Protocol.js:160:17)
2017-04-26T11:42:52.410093+00:00 app[web.1]:       ^
2017-04-26T11:42:52.410098+00:00 app[web.1]:     at emitNone (events.js:86:13)
2017-04-26T11:42:52.410099+00:00 app[web.1]:     at Quit._onTimeout (/app/node_modules/mysql/lib/protocol/sequences/Sequence.js:127:8)
2017-04-26T11:42:52.410099+00:00 app[web.1]:     at Quit.emit (events.js:185:7)
2017-04-26T11:42:52.410100+00:00 app[web.1]:     at ontimeout (timers.js:380:14)
2017-04-26T11:42:52.410101+00:00 app[web.1]:     at tryOnTimeout (timers.js:244:5)
2017-04-26T11:42:52.410102+00:00 app[web.1]:     at Timer.listOnTimeout (timers.js:214:5)

I am hosting my app on Heroku and whenever I try to access this URL the app is crashing forcing me to restart the dyno. The data I am sending is being successfully inserted into the DB but the auto incremented primary key is not being returned to my app. Instead I get a server error.

How can I solve this problem?



via Tyson

No comments:

Post a Comment