loopback icon indicating copy to clipboard operation
loopback copied to clipboard

err: { [Error: ETIMEDOUT] code: 'ETIMEDOUT' } if using 'Model.invoke({}, function(err, result, response){...}'

Open penzhan8451 opened this issue 11 years ago • 5 comments

Hi,

I use loopback rest connector by using Model.invoke() method like below code. But I got an error: err: { [Error: ETIMEDOUT] code: 'ETIMEDOUT' }.

var restConn = require("loopback-connector-rest");
      var dsCfg = {
              connector: restConn,
              debug: true,
              operations: [
                {
                  template: {
                    "method": "POST",
                    "url": posturl,
                    "headers": {
                      "accepts": "application/json",
                      "content-type": "application/json",
                      "Content-Length": payload_str.length,
                      "Authorization": "Bearer " + access_token
                    },
                    "body": payload
                  },
                  functions: {
                    "putToDropbox":[]
                  }
                }
              ]};

    var ds = server.dataSource(dsName, dsCfg);

    var newModel = server.loopback.createModel(boxName,mcfg);
          newModel.attachTo(ds);
          server.model(newModel);
      };

      newModel.invoke({}, function(err, result, response){
         if(err) {
          console.log('err: ', err);
          res.status(400).json({code:-1,msg:'upload file fail.'}).end();
        } else {
          console.log('Result: %j', result);
          res.status(200).json({code:0,msg:'upload file done.'}).end();
        }

      });

But If I use POST directly to ''https://api-content.dropbox.com/1/files_put/auto/' like below code, It can be successful.

var options = { method: 'post', url: 'https://api-content.dropbox.com/1/files_put/auto/', headers: { 'Content-Type': 'application/json', 'Accept':'application/json', 'Content-Length': payload_str.length, 'Authorization': 'Bearer ' + access_token }, body: payload_str };

request(options, cb);

Could you please help have a look ? Thanks.

penzhan8451 avatar Jun 05 '15 02:06 penzhan8451

When Invoke the data (about 28k), this error will occurred. If invoke a very simple data like {name:'xxx',address:'xxxx'}, no errors happened.

penzhan8451 avatar Jun 05 '15 13:06 penzhan8451

Please try to add timeout property to the data source settings to control the timeout of the underlying request module.

Thanks,


Raymond Feng Co-Founder and Architect @ StrongLoop, Inc.

StrongLoop http://strongloop.com/ makes it easy to develop APIs http://strongloop.com/mobile-application-development/loopback/ in Node, plus get DevOps capabilities http://strongloop.com/node-js-performance/strongops/ like monitoring, debugging and clustering.

On Jun 5, 2015, at 6:02 AM, penzhan8451 [email protected] wrote:

When Invoke the data (about 28k), this error will occurred. If invoke a very simple data like {name:'xxx',address:'xxxx'}, no errors happened.

— Reply to this email directly or view it on GitHub https://github.com/strongloop/loopback/issues/1434#issuecomment-109286299.

raymondfeng avatar Jun 05 '15 15:06 raymondfeng

Hi Raymond,

Thanks for your prompt reply! I added 'timeout' property like below:

var restConn = require("loopback-connector-rest");
      var dsCfg = {
              connector: restConn,
              debug: true,
              operations: [
                {
                  template: {
                    "method": "POST",
                    "url": posturl,
                    "headers": {
                      "accepts": "application/json",
                      "content-type": "application/json",
                      "Content-Length": payload_str.length,
                      "Authorization": "Bearer " + access_token
                    },
                    "body": payload
                  },
                  timeout: 10000,
                  functions: {
                    "putToDropbox":[]
                  }
                }
              ]};

The 'ETIMEOUT' error disappear, but another error occurred: err: { [Error: socket hang up] code: 'ECONNRESET' }

I am not sure If this is a network issue (I tried it many times), DO you have any idea or Is there alternative way to do it by loopback rest connector, typically for the size 1M data ?

Thanks in advance.

penzhan8451 avatar Jun 06 '15 10:06 penzhan8451

Hi @penzhan8451 that's a connection error, and it means that the other side has closed the connection. Are you still experiencing the same issue? There are couple of fixes here: http://stackoverflow.com/questions/17245881/node-js-econnreset

loay avatar Sep 20 '16 17:09 loay

Closing this case for inactivity. If you are still experiencing the same issue, please feel free to leave a comment and the case will be re-opened. Thanks.

loay avatar Sep 28 '16 19:09 loay