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

Specify incoming request socket timeout #1113

Open
phillipj opened this issue Dec 19, 2016 · 3 comments
Open

Specify incoming request socket timeout #1113

phillipj opened this issue Dec 19, 2016 · 3 comments

Comments

@phillipj
Copy link

Hi!

I've found an issue allowing long running proxied connections to stay open. In this case, it's something we've seen related to the webpack dev server which has this http-proxy package as its dependency via http-proxy-middleware.

In practise what we've seen is that long running proxied requests are being closed after 2 minutes, even though we specify a longer timeout with the proxyTimeout option. That in turn may make some browser automatically retry the request which failed, which is absolutely not wanted in some scenarios -- the latter isn't really this package's fault, so feel free to ignore that part.

After digging for a while I found the root cause to be in this package's request handler (lib/http-proxy/index.js). By not setting a timeout on the incoming HTTP socket with request.setTimeout(), Node.js core sets 2 minutes by default.

Ideally we'd like to be able to set proxyTimeout to whatever number we want and be sure that's respected. That possibly means using the same value in request.setTimeout().

Does this sound okey to you? Any other thoughts?

Refs webpack/webpack-dev-server#369 (comment)

/cc @Martin-Wegner

@benmosher
Copy link

benmosher commented Jan 19, 2017

FWIW, I was able to work around this via

const LONG_PYTHON_TIMEOUT = 15 * 60 * 1000;
const pythonProxy = new httpProxy.createProxyServer({
  target: {
    host: 'localhost',
    port: pythonPort
  },
  proxyTimeout: LONG_PYTHON_TIMEOUT,
})
app.all('/api/*', (req, res) => 
  pythonProxy.web(req.setTimeout(LONG_PYTHON_TIMEOUT), res))

I just set the request timeout in the handler lambda before passing into the proxy handler itself.

That said: right or wrong, I 100% expected it to set the request timeout for me, mostly because I didn't even know that was a thing until I ran into the timeout in a long test.

So I have no idea what arguments might exist against setting the request timeout inside the proxy handler, but I can't imagine why it would be desirable to let the socket close when the proxy timeout hasn't elapsed. (as someone who has considered it for all of 10 minutes now 😅)

phillipj added a commit to phillipj/node-http-proxy that referenced this issue Mar 17, 2017
This ensures the incoming request does not timeout before the target's
timeout configured with `options.proxyTimeout`

Fixes http-party#1113
@asfernandes
Copy link

Was this fixed or not?

@phillipj
Copy link
Author

Afraid not, sadly there hasn't been any feedback from the maintainers so far.

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

Successfully merging a pull request may close this issue.

3 participants