Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'emit' of null #2226

Closed
djphoenix opened this issue May 29, 2016 · 2 comments
Closed

Cannot read property 'emit' of null #2226

djphoenix opened this issue May 29, 2016 · 2 comments

Comments

@djphoenix
Copy link

Sometimes when making a lot of requests I catching this error:

.../node_modules/request/request.js:83
    socket._httpMessage.emit('error', error)
                       ^

TypeError: Cannot read property 'emit' of null
    at TLSSocket.connectionErrorHandler (.../node_modules/request/request.js:83:24)
    at TLSSocket.g (events.js:286:16)
    at emitOne (events.js:101:20)
    at TLSSocket.emit (events.js:188:7)
    at emitErrorNT (net.js:1272:8)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

Code of request creation:

const request = require('request').defaults({
  baseUrl: api_endpoint,
  method: 'POST',
  json: true,
  gzip: true,
  forever: true,
  timeout: 15000,
});
// ....... //
function api(method, params, token) {
  return new Promise((res,rej)=>{
    var retries = 0;
    const retry = ()=>{
      retries++;
      request({
        uri: method,
        form: params,
      }, (err, resp, body)=>{
        if (err && retries < 5) {
          setTimeout(retry, 500);
        } else if (err) {
          rej(err);
        } else if (body.response != undefined) {
          res(body.response);
        } else if (body.error != undefined) {
          rej(body.error);
        } else {
          rej("Unknown API error");
        }
      });
    };
    retry();
  });
}
@zarenner
Copy link
Contributor

zarenner commented Jun 2, 2016

Duplicate of #1903?

@djphoenix
Copy link
Author

Yes, not found this before. Thx for upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants