简体   繁体   中英

NodeJS server stops listening on port after sometime

My NodeJS server stops listening to requests after some random interval of time(days). My node server is running on 3 load balancers with clusters on 4 nodes each. PM2 logs show that internal cron is still running and I don't think any request is left open that doen't responds.

These are the logs from production server while hitting from inside:

[root@app_inst_1 ~]# curl localhost:3000
curl: (7) couldn't connect to host

PM2 logs:

0|server   | No records found to reconcile
0|server   | undefined

After pm2 restart:

[root@app_inst_1 ~]# curl localhost:3000
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Redirect URL</title>
<script type="text/javascript">
    function postResponse(data) {
        document.write(data);
          CitrusResponse.loadWalletResponse(data);
    }
        var url = window.location.href;
        var index = url.indexOf("#");
        if(index != -1){
            var queryString = url.substring(index + 1);     
            postResponse("#"+queryString);
        }           
</script>
</head>
<body>
</body>

It was actually due to TypeError in javascript. While your application is running with too many logs, you may never dig deep in your log files to look for a TypeError. During the TypeError, the node server doesn't crash but the request made on the port will not be served unless handled using some exception handler or other mechanism, which will result into too many requests being queued up unserved eventually causing the nodejs server port to stop listening for any new requests. So better look into your log files and search for any TypeError.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM