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

Fix flush() to retry fetch() on transient errors #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

penberg
Copy link
Contributor

@penberg penberg commented Jan 21, 2024

This changes flush() to retry the fetch() call on transient errors such as EPIPE, ECONNREFUSED, and ECONNRESET.

const fetch = this.#fetch;
return fetch(request);
} catch (error: any) {
if (isRetryableError(error)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will that really solve the issue?
Don't you need to in the catch of the promise here

this._setClosed(error);
?

Unless fetch throws that error synchronously (I kinda doubt it does), I think it will escape your solution.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mateusfreira I think that point is too late to safely retry because it covers things like failing to process the response. For example, we may have successfully executed a INSERT statement and committed it to the database, but fail later on. Retrying would mean a duplicate insert.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mateusfreira I did switch to catching errors from the promise returned by fetch(), though, and added exponential backoff.

This changes flush() to retry the fetch() call on transient errors such
as EPIPE, ECONNREFUSED, and ECONNRESET.
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 this pull request may close these issues.

2 participants