Node.js app becomes unresponsive if I reload multiple times in quick succession

别来无恙 提交于 2019-12-12 01:10:46

问题


I'm developing a node.js app that displays a single page with map data (which will eventually be updated using an .ajax call).

Right now, my code looks like this:

    app.get('/', function(req, res) {
    postgres.retrieve('SELECT * FROM settings', function(err, proj_data){
        if (err){
            res.send(500);
        }
        else{
            postgres.retrieve('SELECT * FROM report ORDER BY ordering', function(err, report_data){
                res.render('map', {project: proj_data[0], report: report_data});
            });
        }
    });

and postgres.retrieve is a function that uses the node-postgres client:

        retrieve: function(query, complete){
            pg.connect(connection, function(err, client, done){
                client.query(query, function(err, results){
                    if (err){
                        done();
                        return complete(err, null);
                    }
                    else {
                        done();
                        return complete(null, results.rows);
                    }
                });
            });
        },

Currently, if I hit f5 10 times (over, say, 10 seconds), everything seems to respond fine, but right after, memory usage goes way up and the app becomes totally unresponsive. I'm wondering if there's something in my code that's causing this problem.

Thanks!


回答1:


Oops, it seems that this is an issue in Node v0.10.0 +

https://github.com/joyent/node/issues/5108



来源:https://stackoverflow.com/questions/16223347/node-js-app-becomes-unresponsive-if-i-reload-multiple-times-in-quick-succession

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!