Nodejs 应用程序在页面刷新后挂起

Nodejs application hangs after page refresh

请求完成后刷新页面(也就是发出新请求)页面挂起(永远加载)的原因是什么?我该如何调试这个东西?

我的代码类似于:

if(params are not good){
    res.status(500).json("Invalid date.");
}else{
    doDatabaseQuery(callback);
    callback.onSuccess(data) => res.status(200).json(data);
    callback.onError(err) => res.status(500).json(err);
}

如果我更改代码而不是 res.status(200).json(data) 我有 return res.status(200)... 我得到: Can\'t set headers after they are sent. 在超过 1 个请求后。

编辑:

问题似乎是doDatabaseQuery()。此方法仅在猫鼬模型上调用 .find({}) 。当我按下刷新按钮时,异步请求是否没有被终止?

确实是doDatabaseQuery()的问题。对于阅读本文的其他用户:您需要注意的是 nodejs 应用程序确实 kill the async(我以积极的方式说过)但这可能很棘手。因此,请注意您的回调,如果您不确定应用程序挂起的位置,请使用 node-inspector.