http-party / node-http-proxy

A full-featured http proxy for node.js
https://github.com/http-party/node-http-proxy
Other
13.89k stars 1.97k forks source link

Request is being transparently retried #1180

Open abbas-gadhia opened 7 years ago

abbas-gadhia commented 7 years ago

I'm using Cors-Anywhere (https://github.com/Rob--W/cors-anywhere) for proxying my request (which uses node-http-proxy)

After 2 minutes (120 seconds), the request gets retried if there is no response from the server. This behavior was counter-productive for my problem, since if a request is taking long, i dont want to further burden the server with a similar request.

After setting the value for proxyTimeout parameter, this behavior stops.

I dont see this behavior documented anywhere on this project? Should i do so or have i analyzed the problem incorrectly?

Rob--W commented 7 years ago

Can't reproduce, are you sure that it is an issue with either http-proxy or cors-anywhere, and not with your own application or set-up?

I followed the following steps to test this, with Node.js v8.1.3:

  1. Check out cors-anywhere @ https://github.com/Rob--W/cors-anywhere/tree/70400ab166515db9b8fd117f3d208b4960ee846a and run npm install to install the dependencies.
  2. Run node server.js to start CORS Anywhere with default settings.
  3. Start a server that accepts a connection but does not respond to requests, e.g.:

    require('http').createServer(function(req, res) {
        console.log(req.url, req.headers);
        req.once('close', () => { console.log('end of request'); });
    }).listen(9000, '127.0.0.1');
  4. From the command line, run: curl -H 'Origin: null' http://localhost:8080/http://localhost:9000/test -vvv --max-time 300

Result from step 3:

'/test' { origin: 'null',
  accept: '*/*',
  'user-agent': 'curl/7.54.1',
  host: 'localhost:9000',
  connection: 'close' }
end of request

Result from step 4:

*   Trying ::1...
* TCP_NODELAY set
* connect to ::1 port 8080 failed: Connection refused
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /http://localhost:9000/test HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.54.1
> Accept: */*
> Origin: null
> 
< HTTP/1.1 404 Not Found
< Access-Control-Allow-Origin: *
< Date: Thu, 13 Jul 2017 21:12:13 GMT
< Connection: keep-alive
< Transfer-Encoding: chunked
< 
* Connection #0 to host localhost left intact
Not found because of proxy error: Error: socket hang up