1

In the Sails.js app I'm developing, I got randomly an ECONNREFUSED error. I've tried to check the piece of code that is throwing an error, but with no luck. I already switched on the logs to verbose (NODE_DEBUG environment variable set to 'net') and I got this:

NET 6070: onread 11
NET 6070: got data
NET 6070: _read
NET 6070: _read
NET 6070: _read wait for connection
NET 6070: pipe false undefined
NET 6070: connect: find host 127.0.0.1
NET 6070: connect: dns options [object Object]
NET 6070: onread 8680
NET 6070: got data
NET 6070: _read
NET 6070: afterConnect
NET 6070: destroy
NET 6070: close
NET 6070: close handle
verbose: Lowering sails...
verbose: Sent kill signal to child process (6080)...
verbose: Shutting down HTTP server...
NET 6070: SERVER _emitCloseIfDrained
NET 6070: SERVER handle? false   connections? 11
events.js:85
      throw er; // Unhandled 'error' event
        ^
Error: connect ECONNREFUSED
    at exports._errnoException (util.js:746:11)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1010:19)

I really don't know what's wrong here...

UPDATE

While I'm debugging with node-inspector, the error disapear. Strange!

2 Answers 2

2

Basically, as per the log you are showing, events.js:85 that file is throwing an error at that line (I know, its obvious i'm just describing everything). Now, without that code it will be impossible to debug why the error is being thrown. But, i believe that there is a method/function call at that line that is throwing said error, and it's not wrapped in a try/catch block, my suggestion is to wrap it and log the error message in order to check what's going on.

I've been doing some research and stumbled upon many errors that where all pointing to events.js:85. It seems to be something related to the port you are using to run your application. Most solutions point out that you should either choose a random port or change the port you are using in your app.

Source here.

3
  • events.js it's a file from the Sails.js core, I think. It's not code written by me..
    – Ze Luis
    Sep 10, 2015 at 17:16
  • 1
    It seems to be a file from nodejs. I've updated my answer with a link that may help you fix your issue.
    – taxicala
    Sep 10, 2015 at 17:34
  • Thank you for your effort trying to help me. I'm running on port 2000 on a linux system, that means that I don't need any root permissions( see this ). What is strange is that my app ends unexpectedly, after some random number of successfully requests.
    – Ze Luis
    Sep 10, 2015 at 17:45
0

I figured out what's wrong. It was a https request without an error callback.

Example:

var request = require('https').request(requestOptions, function (response) {
    //logic here
});

request.on('error', function (err) {
    //error handling here
});
request.end();

I missed the 'error' callback. The ECONNREFUSED was throwed by the request that, at some point, was not completed successfully, and throwed that error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.