我使用了Node js express框架,在我的一个函数中,我试图通过使用http.post()方法调用我的另一个服务器API。
大多数情况下它都能流畅地运作。但是在随机的时间;当成功响应从http post返回时,所有进行中的请求或db操作都会陷入死锁。即使Node正在运行。
现在要解决这个问题,我需要重新启动Node。 //进口
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);
}
}
任何帮助表示感谢。