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

client(_:shouldRetry:error:attempts:): Only one retry attempt is allowed? #97

Closed
AndrewSB opened this issue Mar 3, 2025 · 4 comments
Closed

Comments

@AndrewSB
Copy link
Contributor

AndrewSB commented Mar 3, 2025

i don't understand the docstring next to this function. this is the implementation of the function

private func performRequest<T>(attempts: Int = 1, send: () async throws -> T) async throws -> T {
    do {
        return try await send()
    } catch {
        guard let error = error as? DataLoaderError else {
            throw error
        }
        guard try await delegate.client(self, shouldRetry: error.task, error: error.error, attempts: attempts) else {
            throw error.error
        }
        return try await performRequest(attempts: attempts + 1, send: send)
    }
}

it looks like if i return true from my APIClientDelegate it'll retry forever.

where is the "only one retry attempt" enforcement done? and what do i do if i want to retry once immediately, and then again after 5 seconds, for example

@richardtop
Copy link

  1. I think, in the delegate you need to check whether it's your 1st or 2nd attempt etc.
  2. I think an exponential decay behavior should be either incorporated in the library or be built on top of this library, i.e. a caller of the HTTP client waiting and issuing the request again.

@AndrewSB
Copy link
Contributor Author

@kean could you confirm? the docs here don't make sense. why is Only one retry attempt is allowed.? afaict i can retry as much as i want

https://kean-docs.github.io/get/documentation/get/apiclientdelegate/client(_:shouldretry:error:attempts:)-4lwvz/

@kean
Copy link
Owner

kean commented Mar 19, 2025

"Gets called after a networking failure. Only one retry attempt is allowed." – seems like it's outdated. It was probably written before the attempts parameter was added.

@AndrewSB
Copy link
Contributor Author

👍

should update the docs, makes sense. i have full control of retry attempts. thanks @kean

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

3 participants