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

Handle connection errors with RetryMiddleware #513

Open
simonhaenisch opened this issue May 21, 2024 · 2 comments
Open

Handle connection errors with RetryMiddleware #513

simonhaenisch opened this issue May 21, 2024 · 2 comments

Comments

@simonhaenisch
Copy link

I tried basically this:

const { RetryMiddleware } = require('mappersmith/middleware')

RetryMiddleware({
  retries: 1,
  validateRetry: (res) => res.error() !== null,
})

but it doesn't even get to the middleware I think, because the exception throws before the middleware has a chance to handle it (ECONNREFUSED in my case but I want to handle ECONNRESET because it happens with keep-alive enabled when the server closes the connection).

Do I need to write my own variant of the RetryMiddleware that is also able to catch the promise rejection and retry on that as well?

@simonhaenisch
Copy link
Author

simonhaenisch commented May 21, 2024

I looked at the implementation of RetryMiddleware and it does allow you to retry on rejection as well. Reason it doesn't work for me is because the request method was POST not GET, and it only enables retries for get requests (not sure yet how to enable it for other methods).

@simonhaenisch simonhaenisch closed this as not planned Won't fix, can't repro, duplicate, stale May 21, 2024
@simonhaenisch simonhaenisch reopened this May 21, 2024
@simonhaenisch
Copy link
Author

simonhaenisch commented May 24, 2024

After looking through the issues and reading through the ones explaining why you shouldn't retry anything except GET because of idempotency, I believe this is a new use-case for allowing retries on all http verbs... "this" being the type of exception where we know the request never reached the server, e.g. connection reset (ECONNRESET). In that case the method doesn't matter, the request is always retry-able?

Node.js has keep-alive enabled by default in newer versions (20+), and if the client's socket timeout is higher than the server's keep-alive timeout, you easily end up with a connection reset, thus it's not so uncommon anymore.

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

No branches or pull requests

1 participant