Retry on certain errors #426

Closed
TrevorBurnham opened this Issue May 23, 2013 · 5 comments

Comments

Projects
None yet
3 participants
@TrevorBurnham

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.

@jcrugzz

This comment has been minimized.

Show comment
Hide comment
@jcrugzz

jcrugzz May 23, 2013

Member

@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 :).

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

@TrevorBurnham

This comment has been minimized.

Show comment
Hide comment
@TrevorBurnham

TrevorBurnham 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.

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.

@wmertens

This comment has been minimized.

Show comment
Hide comment
@wmertens

wmertens May 18, 2018

@TrevorBurnham did you ever fix this? I want to make a small proxy that holds requests while the service process restarts…

@TrevorBurnham did you ever fix this? I want to make a small proxy that holds requests while the service process restarts…

@TrevorBurnham

This comment has been minimized.

Show comment
Hide comment
@TrevorBurnham

TrevorBurnham May 18, 2018

@wmertens Not sure. I’m no longer working on that proxy project.

@wmertens Not sure. I’m no longer working on that proxy project.

@wmertens

This comment has been minimized.

Show comment
Hide comment
@wmertens

wmertens May 18, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment