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

ELIFECYCLE error #359

Open
martynas3336 opened this issue Jun 17, 2021 · 0 comments
Open

ELIFECYCLE error #359

martynas3336 opened this issue Jun 17, 2021 · 0 comments

Comments

@martynas3336
Copy link

Hi.

I am very rarely experiencing ELIFECYCLE error and I suspect it is caused by a needle.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-06-15T08_41_46_354Z-debug.log
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the xxx-xxx-xxx-xxx@0.0.0 start script.
npm ERR! xxx-xxx-xxx-xxx@0.0.0 start: `node ./server.js`
npm ERR! errno 1
      throw er; // Unhandled 'error' event
    at TLSWrap.onerror (_tls_wrap.js:416:11)
    at TLSSocket._emitTLSError (_tls_wrap.js:888:10)
    at TLSSocket.EventEmitter.emit (domain.js:467:12)
    at TLSSocket.emit (events.js:315:20)
    at TLSSocket.socketErrorListener (_http_client.js:469:9)
Emitted 'error' event on ClientRequest instance at:
Error
      ^
events.js:292
    at TLSWrap.callbackTrampoline (internal/async_hooks.js:131:14)\

Whenever this error appears it is only always after a successful request when using needle. At least the 5 times it happened during the last 2 months every time I got a 200 response just before the crash. I suppose it is possible, that after a successful request an error can still be emitted. Correct me if im wrong.

I do have a very heavy traffic and the reproduction rate is <0.1%

After going deeper in to the source code I found this block in lib/needle.js. I guess this is the part where a successful request is being handled:

  function done(err, resp) {
    if (returned++ > 0)
      return debug('Already finished, stopping here.');

    if (timer) clearTimeout(timer);
    request.removeListener('error', had_error);

    if (callback)
      return callback(err, resp, resp ? resp.body : undefined);

    // NOTE: this event used to be called 'end', but the behaviour was confusing
    // when errors ocurred, because the stream would still emit an 'end' event.
    out.emit('done', err);
  }

Note the line 465: request.removeListener('error', had_error);
This removes the 'error' event listener from http.RequestClient that needle uses.

Could this be that needle removes 'error' event listener and for some unknown reasons http.ClientRequest tries to emit an 'error' afterwards?

Because if so, an aplication is going to crash nonetheless.

Here is a reference to Event Emitter: https://nodejs.org/api/events.html
It states that

If an EventEmitter does not have at least one listener registered for the 'error' event, and an 'error' event is emitted, the error is thrown, a stack trace is printed, and the Node.js process exits.

Thanks in advance

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

1 participant