Skip to content

feat: retry layer#378

Merged
gregorydemay merged 18 commits intomainfrom
gdemay/XC-287-retry-layer
Mar 11, 2025
Merged

feat: retry layer#378
gregorydemay merged 18 commits intomainfrom
gdemay/XC-287-retry-layer

Conversation

@gregorydemay
Copy link
Contributor

@gregorydemay gregorydemay commented Mar 6, 2025

Follow-up on #370, #364, #374, and #375 to automatically retry requests by doubling its max_response_bytes when the response was too big.

Base automatically changed from gdemay/XC-287-json-rpc-layer to main March 7, 2025 07:41
@gregorydemay gregorydemay force-pushed the gdemay/XC-287-retry-layer branch from b102478 to 0a0297a Compare March 7, 2025 09:14
@gregorydemay gregorydemay marked this pull request as ready for review March 7, 2025 15:34
@gregorydemay gregorydemay requested a review from a team as a code owner March 7, 2025 15:34
@gregorydemay gregorydemay requested review from lpahlavi and ninegua March 7, 2025 15:34
impl Client {
/// Create a new client returning custom errors.
pub fn new_with_error<CustomError: From<IcError>>(
) -> impl Service<IcHttpRequestWithCycles, Response = IcHttpResponse, Error = CustomError> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are some subtle issues here at play, which is the reason why I needed yet another type of conversion to somewhat emulate map_err but with a concrete type:

  1. The main issue is that in order to be able to use tower::retry, the service needs to be Clone.
  2. The current return type, because its an impl Something cannot be Clone.
  3. To be clone, we would need to return the exact type, which we cannot do because map_err only takes a closure (FnOnce) and unfortunately no concrete type can implement the FnOnce trait (see Rust issue 29625).
  4. We could try to use BoxService or BoxCloneService on Client to do type erasure but this also won't work because it requires the future type of the service to be Send + 'static which cannot be derived because the future of Client is not exposed by the ic_cdk so we have to resort to using <Box<dyn Future>>

All of that to say feel free to chime in if you have better ideas 🙈 .

Copy link
Contributor

Choose a reason for hiding this comment

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

I can't say I have a better idea... Maybe @ninegua ?

Copy link
Contributor

@lpahlavi lpahlavi left a comment

Choose a reason for hiding this comment

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

@gregorydemay Thanks a lot for this PR! Looks very good in my opinion.

impl Client {
/// Create a new client returning custom errors.
pub fn new_with_error<CustomError: From<IcError>>(
) -> impl Service<IcHttpRequestWithCycles, Response = IcHttpResponse, Error = CustomError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't say I have a better idea... Maybe @ninegua ?

@@ -99,9 +99,11 @@
//! # }
//! ```
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe you could actually add an example with error conversion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea, done.

Copy link
Contributor Author

@gregorydemay gregorydemay left a comment

Choose a reason for hiding this comment

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

Thanks @lpahlavi for the review!

@@ -99,9 +99,11 @@
//! # }
//! ```
Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea, done.

Copy link
Contributor

@lpahlavi lpahlavi left a comment

Choose a reason for hiding this comment

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

Thanks for adding the docs example, LGTM!

@gregorydemay gregorydemay merged commit ab1c1cd into main Mar 11, 2025
10 checks passed
@gregorydemay gregorydemay deleted the gdemay/XC-287-retry-layer branch March 11, 2025 14:31
gregorydemay added a commit to dfinity/canhttp that referenced this pull request Jul 9, 2025
Follow-up on dfinity/evm-rpc-canister#370, dfinity/evm-rpc-canister#364, dfinity/evm-rpc-canister#374, and dfinity/evm-rpc-canister#375 to automatically retry requests
by doubling its `max_response_bytes` when the response was too big.
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