socket Hangup

时间:2017-05-25 12:14:00

标签: node.js express aws-lambda

我的问题如下:

abc lambda触发另一个lambda(名为:khjj)  对我来说一切都很顺利只有在cloudwatch日志中,甚至在本地,如果我运行abc lambda函数来触发khjj lambda,我的请求后会出现socket hangup错误。

我的abc lambda从dynamo db表中读取一个数据,逐行触发khjj函数,abc lambda中的代码为:

    var sendData = module.exports = {
     data : function(){
    return new Promise(function (resolve, reject) {
     arrayData = []

  // here table.get is a function in the same file for getting the 
    // data from the dynamo db table
    table.get("Table1").then(function(response){
    _.forEach(response, function(data){
      var obj = {};
      obj.value1 = data.value1;
      obj.value2 = data.value2;  
      obj.value3 = data.value3;
      obj.value4 = data.value4;
      obj.value5 = data.value5;
      obj.value6 = data.value6;
      obj.value7 = data.value7;
      arrayData.push(obj)
    })
    Promise.all(arrayData).then(function(objs){
      async.each(objs, function(data, callback){
        request({
          headers: {'Content-Type':'application/json'},
          url : // here I used lambda khjj url here,
          method: 'POST',
          body: company,
          json: true
      }, function (err, res, body) {
          if(!_.isNil(err)){
            console.log(err);
            console.log('error in triggering')
          } else {
            // tried this callback as well to stop that error of socket hangup
            callback(null, 'success')
          }
          })
        }, function(err){
          console.log()
        })
      }, function(err){
         console.log(err)
      })
    }, function(err){
      console.log('error in getting data from table :', err)

    })
  resolve(true);
})
 }

现在上面的lambda函数触发了“khjj”lambda,所以我在“khjj”lambda函数中使用了awsServerlessExpress函数,因此它在代码中获取请求:

    app.post('/called/by/abc/lambda', function(req, 
     resp){
      check.message(request).then(function(response){
      resp.write('success')
      resp.end();
      }, function(err){
         console.log(err)
       resp.end();
    })
   })

套接字错误来自上面的lambda,即khjj,在整个网络中搜索甚至stackoverflow和aws论坛也没有得到任何解决方案

甚至考虑过这个网站:https://gregjs.com/javascript/2015/how-to-scrape-the-web-gently-with-node-js/

请任何帮助都没关系。感谢。

CloudWatch错误:

    2017-05-25T13:30:15.043Z    009c3110-414e-11e7-99b5-b3bd2686fba3    
    { Error: socket hang up
    at createHangUpError (_http_client.js:253:15)
    at Socket.socketOnEnd (_http_client.js:345:23)
    at emitNone (events.js:91:20)
     at Socket.emit (events.js:185:7)
     at endReadableNT (_stream_readable.js:974:12)
     at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickDomainCallback 
    (internal/process/next_tick.js:128:9) code: 'ECONNRESET' }

1 个答案:

答案 0 :(得分:0)

我解决了上面的问题,错误的发生只是因为代码中的某个地方我没有处理承诺拒绝正确。