Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 节点js http请求陷入死锁_Node.js - Fatal编程技术网

Node.js 节点js http请求陷入死锁

Node.js 节点js http请求陷入死锁,node.js,Node.js,我使用了NodeJSExpress框架,在我的一个函数中,我试图使用http.post方法调用我的另一个服务器API 大多数情况下,它工作流畅。但在随机时间;当http post返回成功响应时,所有正在进行的请求或db操作都将进入死锁。即使节点正在运行 为了解决这个问题,我需要重新启动节点。 //进口 var async = require("async"); var request = require("request"); var wlogger = requ

我使用了NodeJSExpress框架,在我的一个函数中,我试图使用http.post方法调用我的另一个服务器API

大多数情况下,它工作流畅。但在随机时间;当http post返回成功响应时,所有正在进行的请求或db操作都将进入死锁。即使节点正在运行

为了解决这个问题,我需要重新启动节点。 //进口

var async       = require("async");
var request       = require("request");
var wlogger     = require('../config/logger');
//功能代码

exports.sendNotification = function( req, res, next ) {
try 
{
    if (req.session && req.session.publish_UserName) {

            var data = {"request":"callback@create","data":{"userId":req.body.userId}};

            var httpReq=request.post({
                headers: {'content-type' : 'application/json'},
                url:     config.api_url,
                form:   data
            },function(error, response, body){

               wlogger.info({userName: req.session.publish_UserName, action: '/sendNotification', requestData:data, responseData :response,responseCode: '200', message: "/ - sendNotification - Notification sent"}); // write in log //
            })
            httpReq.end();
            res.send({"success": true, "status": 200, "message": "Notification sent."});


    }else{
        wlogger.info({userName: 'anonymous', action: '/sendNotification', requestData: req.body, responseData : '',responseCode: '500', message: "/ - sendNotification - Session not available "}); // write in log //
        res.redirect('/accountlogin');
    }
} catch(err){
    wlogger.error({userName: ((req.session.UserName)?req.session.Plan_UserName:'anonymous'), action: '/sendNotification', requestData: req.body, responseData : '',responseCode: '500', message: '/sendNotification catchException - '+JSON.stringify(err)}); // write in log //
    res.status(500).json(err.message);
}
}


非常感谢您的帮助。

您能多加一点背景吗?最好至少是您的代码段所使用的整个函数,以及request和config的定义/要求/导入。@Kaivosukeltaja此问题是随机出现的。我发现了此问题。我想在请求结束之前释放所有数据库连接/资源。