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

run(): Retry Mechanism #11

Open
ChrisTalman opened this issue Dec 31, 2018 · 6 comments
Open

run(): Retry Mechanism #11

ChrisTalman opened this issue Dec 31, 2018 · 6 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@ChrisTalman
Copy link

ChrisTalman commented Dec 31, 2018

Transient failures can sometimes cause a query to fail at one moment, but be capable of running successfully a moment later. For instance, network instability or limited database system resources.

Could it be useful for the driver to provide a retry mechanism of some kind which can be enabled by specifying an option to run()? The same option could also be provided as part of the connection options, so that retry is conducted by default without being explicitly specified for every run().

Up to now, I have written a kind of wrapper around the driver which extends the functionality of run() with a retry mechanism. However, this seems like the sort of thing which could be useful to have built into the driver itself.

A simple exponential backoff would probably work for most use cases. If greater flexibility were required, the user could provide a callback to manage the backoff themselves.

I imagine that retry would only be conducted for errors likely to be transient, like a timeout. It would probably not make sense to retry for errors like a duplicate primary key.

@ronzeidman
Copy link

ronzeidman commented Jan 1, 2019 via email

@ChrisTalman
Copy link
Author

ChrisTalman commented Jan 2, 2019

Sounds good, can you share your wrapper?

It was essentially just a method which would run a query within a try...catch block using await. If it ran successfully, the result would be returned. If it failed, it would be retried after a short delay, starting at 200ms, and doubling on each failure. If it failed 3 times, the last error would be thrown.

For what exceptions exactly are you retrying?

I needed the functionality quickly, and so at the time I decided to simply retry on all errors. It would be preferable to only retry on appropriate errors. I'm not familiar with the driver protocol, so I'm not aware of the full range of potential errors. I can't remember the precise form of the transient errors I experienced in the past, but their error messages were generally concerning a connection timeout or reset. Using this page as a reference, these might be reasonable candidates: ReqlTimeoutError, ReqlAvailabilityError, ReqlInternalError, and perhaps ReqlDriverError.

Do you also reconnect or just resending the query?

I just resend the query, although I suppose it's plausible that a transient error could be due to a connection failure which needs resolution in the driver.

Are you using the connection pool?

Yep.

@GaikwadPratik
Copy link

@ronzeidman @ChrisTalman

Did you get a chance to work on this further?

@ChrisTalman
Copy link
Author

I've just been using the function I wrote for myself.

@atassis
Copy link
Collaborator

atassis commented May 24, 2020

@ChrisTalman Hello there. I am starting to contribute widely to this repo. I would like to provide this kind of feature for the driver. Can you share your function for faster development? If not, it'll take much longer for this task being reached.

@atassis atassis added enhancement New feature or request help wanted Extra attention is needed labels May 24, 2020
@ChrisTalman
Copy link
Author

Hey @atassis. The code is here.

It makes use of my own delay() method, but that can be easily substituted.

I hope you find it in some way useful. It wasn't exhaustively planned out, and so it may not be the most elegant implementation. But, it has seemed to serve me very well for quite some time at this point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants