0

This error comes after 8-10 hours of my web services running continously with forever module.

{
    "date": "Wed Sep 13 2017 21:22:25 GMT+0000 (UTC)",
    "process": {
        "pid": 24337,
        "uid": 1000,
        "gid": 1000,
        "cwd": "/path/to/my/file/",
        "execPath": "/path/to/my/nvm/.nvm/versions/node/v4.4.5/bin/node",
        "version": "v4.4.5",
        "argv": ["/path/to/my/nvm/.nvm/versions/node/v4.4.5/bin/node", "/path/to/my/file/app.js"],
        "memoryUsage": {
            "rss": 133083136,
            "heapTotal": 83753568,
            "heapUsed": 71120576
        }
    },
    "os": {
        "loadavg": [0.0029296875, 0.0146484375, 0.04541015625],
        "uptime": 397147
    },
    "trace": [{
        "column": 13,
        "file": "/path/to/my/file/node_modules/mysql/lib/protocol/Protocol.js",
        "function": "Protocol.end",
        "line": 109,
        "method": "end",
        "native": false
    }, {
        "column": 28,
        "file": "/path/to/my/file/node_modules/mysql/lib/Connection.js",
        "function": "",
        "line": 102,
        "method": null,
        "native": false
    }, {
        "column": 20,
        "file": "events.js",
        "function": "emitNone",
        "line": 72,
        "method": null,
        "native": false
    }, {
        "column": 7,
        "file": "events.js",
        "function": "Socket.emit",
        "line": 166,
        "method": "emit",
        "native": false
    }, {
        "column": 12,
        "file": "_stream_readable.js",
        "function": "endReadableNT",
        "line": 913,
        "method": null,
        "native": false
    }, {
        "column": 9,
        "file": "node.js",
        "function": "nextTickCallbackWith2Args",
        "line": 442,
        "method": null,
        "native": false
    }, {
        "column": 17,
        "file": "node.js",
        "function": "process._tickDomainCallback",
        "line": 397,
        "method": "_tickDomainCallback",
        "native": false
    }],
    "stack": ["Error: Connection lost: The server closed the connection.", "    at Protocol.end (/path/to/my/file/node_modules/mysql/lib/protocol/Protocol.js:109:13)", "    at Socket.<anonymous> (/path/to/my/file/node_modules/mysql/lib/Connection.js:102:28)", "    at emitNone (events.js:72:20)", "    at Socket.emit (events.js:166:7)", "    at endReadableNT (_stream_readable.js:913:12)", "    at nextTickCallbackWith2Args (node.js:442:9)", "    at process._tickDomainCallback (node.js:397:17)"],
    "level": "error",
    "message": "uncaughtException: Connection lost: The server closed the connection.",
    "timestamp": "2017-09-13T21:22:25.271Z"
}

couldnt find out why this is happening? i have also checked whether my databse is going idle or not but my db is perfect it is not going idle. Then what else is killing my node process? i have done several research on which is killing my API'S i had no idea .then i started logging the requests through api then i found out this error message and this comes only after several hours of continous processing.

Jagadeesh
  • 1,967
  • 8
  • 24
  • 47

1 Answers1

2

You can see in that stack trace that your connection to the MySQL database is being closed by the MySQL server itself.

This issue gives a bit of a background as to why the server may disconnect you and how you can increase the MySQL server timeout.

Here is a similar question with an answer that describes how to handle this particular error event within your Node.js app itself. This is useful for reconnecting to the MySQL server on the fly when disconnected.

You should be able to prevent your application from these database timeouts if you safely reconnect as per the examples in that second link. It is a more rigid solution than simply extending the timeout length, especially as you don't have to fully rely on behaviour that is external to your application.

kostak
  • 98
  • 7
  • i am getting this error on following the second one { [Error: ER_CON_COUNT_ERROR: Too many connections] code: 'ER_CON_COUNT_ERROR', errno: 1040, sqlState: undefined, fatal: true } – Jagadeesh Sep 15 '17 at 12:48