Skip to content

Retry on certain errors #426

TrevorBurnham opened this Issue May 23, 2013 · 2 comments

2 participants


I'd like to send the request again when the server being proxied exhibit certain behaviors. Is this possible? I've tried doing this:

proxy.on('proxyError', function(err, req, res) {
  if (err.code === 'ECONNREFUSED') {
    process.nextTick(function() {
      proxy.proxyRequest(req, res, proxyOptions);

But, this doesn't appear to send the request to the server again, and no response is ever given to the client.

nodejitsu member
jcrugzz commented May 23, 2013

@TrevorBurnham Try removing the process.nextTick. You want to ensure that the socket of the response has not already closed in order to be able to retry the proxy. I believe you can check res.connection.destroyed.

I am guessing that the wait time of process.nextTick is too long so the underlying TCP socket is already closed. Reopen the issue if you can't get it to work :).

@jcrugzz jcrugzz closed this May 23, 2013

Thanks for the quick response. Unfortunately, removing process.nextTick doesn't seem to have any effect. The scenario I'm testing is:

  1. I shut down the server,
  2. I start the proxy,
  3. The client sends a request via the proxy, and
  4. Then I start the server

Logging the err argument, I'm seeing a bunch of ECONNREFUSEDs alternating with a bunch of ETIMEDOUTs—whether I ever start the server or not. The server never receives a request, and the client never receives a response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.