node-http-proxy icon indicating copy to clipboard operation
node-http-proxy copied to clipboard

test suite fails w/ ECONNREFUSED

Open jfis opened this issue 15 years ago • 14 comments

I'm running into issues that seem like a problem with just my system but I was hoping to find some assistance.

node 0.4.7
http-proxy 0.5.0
vows 0.5.8
colors 0.5.0
optimist 0.2.0
request 1.9.5
socket.io 0.6.17
on mac os x 10.6.7

When I run

 vows test/*-test.js --spec

all tests fail that are not expecting a 404 or 500.

The errors look like this:

When using server created by httpProxy.createServer() with no latency and a valid target server
✗ should receive 'hello localhost'
» expected 'hello localhost',
got  'An error has occurred: {"stack":"Error: ECONNREFUSED, Connection refused\\n    
at Socket._onConnect (net.js:599:18)\\n    at IOWatcher.onWritable [as callback 
(net.js:186:12)","message":"ECONNREFUSED, Connection      
refused","errno":61,"code":"ECONNREFUSED","syscall":"connect"}' (==) // helpers.js:77

Anyone seen this before? Seems like I'm missing something important. There is very little information on ECONNREFUSED. I do know that the error happens on making the request from proxy to target using the 'request' module (which is expected given the error) but I can't determine why. I'm hoping there's something simple I missed.

jfis avatar May 10 '11 17:05 jfis

ECONNREFUSED is a generic node.js error message when a socket cannot make a connection. It usually indicates that the listening server isn't infact listening, or the outgoing request you made to the server could not find its target.

With that being said, I'm not entirely sure what your issue is. Could it be possible you are already running services on the port http-proxy is trying to use for it's tests? Maybe you could change the port number in the test files?

@indexzero - Do you have any ideas why this could be happening?

Marak avatar May 10 '11 18:05 Marak

Thanks for the response. The ports are already varied so every test shouldn't fail if it had to do with port. I took a shot anyway and I did mix them up but no change.

To add to this mystery... I get the exact same results on my ubuntu 10.10 vps with the same node, npm, and module versions.

jfis avatar May 10 '11 18:05 jfis

What versions of node and npm are you running?

indexzero avatar May 10 '11 18:05 indexzero

I just ran the test suite locally on my machine, and I can confirm I am seeing the same errors in the test suite. Right now I'm going to assume that it's a regression from an update to node.js core.

I'm in SF until the weekend, so I may not have time to properly address this until Monday.

indexzero avatar May 10 '11 19:05 indexzero

No worries on time table. I'm just glad someone else can replicate.

I see I forgot npm in the original.

node 0.4.7
npm 1.0.6
http-proxy 0.5.0
vows 0.5.8
colors 0.5.0
optimist 0.2.0
request 1.9.5
socket.io 0.6.17

jfis avatar May 10 '11 19:05 jfis

I tried to reverting back to node v0.4.6 and I got the same results. I'm on HEAD right now though, so I'm going to revert back to individual commits until this is passing. I always ensure the entire test suite passes before any release so it's strange that this regression popped up here on a stable tag

indexzero avatar May 10 '11 21:05 indexzero

I can confirm that on v0.4.6 the following commit passes all HTTP tests: ddf31b22ec71ef9dacca9c178ee26b6314d9fdf4. I'm upgrading back to v0.4.7 to test this as well now. This may be a bad rebase in node.js core because the only difference here is the underlying agent API change from this pull request: https://github.com/nodejitsu/node-http-proxy/pull/39

indexzero avatar May 10 '11 21:05 indexzero

{protocol}.getAgent() method signature http://nodejs.org/docs/v0.4.7/api/http.html#http.getAgent (I don't see getAgent for https in the docs?)

If I change these lines in node-http-proxy.js:

function _getAgent (host, port, secure) {
//var options = { host: host, port: port };
//var agent = !secure ? http.getAgent(options) : https.getAgent(options);
var agent = !secure ? http.getAgent(host, port) : https.getAgent(host, port);

agent.maxSockets = maxSockets;
return agent;
}

Everything seems to work then.

Then I found this haha https://github.com/joyent/node/issues/943

jfis avatar May 10 '11 21:05 jfis

And there's already a pull request

https://github.com/nodejitsu/node-http-proxy/pull/45

jfis avatar May 10 '11 21:05 jfis

Something is wrong in core. The method signature you suggest is not the correct method signature. This may be the result of a bad rebase on behalf of @ry.

In master both https.js and http.js indicate that both .getAgent() methods take an options hash, not a host, port pair, but in v0.4.7 it is still inconsistent. However, there is a commit from @mikeal rebased into February that actually fixes this.

Old commit that fixes this https://github.com/joyent/node/commit/2b03ba59177fee8ad28b5be0bebd149b06f3c2a2#lib/http.js

v0.4.7 https.js: https://github.com/joyent/node/blob/v0.4.7/lib/https.js#L70 http.js: https://github.com/joyent/node/blob/v0.4.7/lib/http.js#L1408

master http.js: https://github.com/joyent/node/blob/master/lib/http.js#L1418 https.js: https://github.com/joyent/node/blob/master/lib/https.js#L80

I would like to suggest a hotfix release for nodejs as v0.4.7-1 or v0.4.8 to resolve this inconsistency. If that's not a good plan I can always just revert node-http-proxy to the original code under v0.5.0 that works around this inconsistency.

This issue should also be closed: https://github.com/joyent/node/issues/943 and is discussed more: https://github.com/nodejitsu/node-http-proxy/issues/38

indexzero avatar May 10 '11 22:05 indexzero

Yea I meant that signature only for comparison. It's what will work with 0.4.7. Options hash makes more sense.

I agree that node-http-proxy should not be modified.

It's just good to know about this incompatibility if others have issues.

Thanks all.

jfis avatar May 10 '11 22:05 jfis

I reverted 642e15805dbd572835bb4fee9527e4f2da658833 in 40dc9dee2d1e617af7f85a056d281b4f220f2802 and rolled this up into 0.5.1. Confirmed all tests passing on node v0.4.7. I will address the above discussion when the next version of node is released.

indexzero avatar May 10 '11 22:05 indexzero

the fix only went in to master, not in to 0.4.x, because while this is a "bug" the fix for the bug makes 0.4.future not forward compatible.

mikeal avatar May 10 '11 22:05 mikeal

@mikeal Thanks for clarifying. In master now there is a backwards compatible change that checks the type of the arguments passed to .getAgent(). Would love to see a hotfix version pushed out from @ry, but now that I've reverted it's not a big deal.

indexzero avatar May 10 '11 22:05 indexzero