Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

ECONNREFUSED causes node process to exit #136

Closed
pascalopitz opened this issue May 9, 2010 · 8 comments
Closed

ECONNREFUSED causes node process to exit #136

pascalopitz opened this issue May 9, 2010 · 8 comments

Comments

@pascalopitz
Copy link

Hello,

if the connection is refused, HTTP client exits.
Example:

var sys = require('sys'), http = require('http');

var node = {
"host" : "127.0.0.1", // local host
"port" : "8300" // randon port that is not listening
};

try{
var client = http.createClient(node.port, node.host);
var request = client.request('GET', '/', {"host" : node.host});
request.addListener('response', function (response) {
if(response.statusCode == 200) {
sys.puts(node.host+':'+node.port+' active');
_active = node;
}
});
request.addListener('error', function (response) {
sys.puts('error');
});
request.end();
} catch(e) {
sys.puts('catch here');
}

$ node test-refused.js Error: ECONNREFUSED, Connection refused at IOWatcher.callback (net:757:22) at node.js:176:9

Should there not be an event that catches this, i.e. "refused"?

@pascalopitz
Copy link
Author

Sorry, this misformats.
Pastie here:

http://pastie.org/952560

Raw text:
http://pastie.org/952560.txt

@ry
Copy link

ry commented May 9, 2010

catch the 'error' event. your port should be an integer.

@pascalopitz
Copy link
Author

Port as integer makes no difference.
Is this because in the server it would create a socket?

Catching the error event of the client worked. Thanks, that wasn't entirely obvious.

Working code:
http://pastie.org/952790

@ry
Copy link

ry commented May 10, 2010

can you check to see if you see this issue on the latest HEAD ?

@pascalopitz
Copy link
Author

Sorry ry, not sure which issue we're talking about?
I can see that you changed http.js in order to utilize isPort, but this isn't relevant for the client behaviour outlined above, therefore your comment "your port should be an integer" wasn't relevant for the issue I had.

As you pointed out correctly, catching the error event worked to prevent node.js from exiting, just that the error event handler is to be attached to the client, not the request.

Therefore not a bug in my eyes, but maybe should be documented somehow.

Thanks for your help.

@ry
Copy link

ry commented May 10, 2010

cool. closing.

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants