fix(wallet_esplora): Gracefully handle 429s errors#59
fix(wallet_esplora): Gracefully handle 429s errors#59realeinherjar wants to merge 1 commit intobitcoindevkit:masterfrom realeinherjar:einherjar/fix-429s
Conversation
evanlinjin
left a comment
There was a problem hiding this comment.
Aproach NACK
Thank you for taking a shot at this.
Why 500ms? What if the server expects us to wait for 600ms? I would prefer if we checked the Retry-After header. If that does not exist, then have an exponential back-off delay as a fallback.
Do we need the async recursion? Is there a way to do it with a loop?
I also think introducing tokio as an async dependency is a big ask. Would it be trivial to implement a simple Future using Instant?
|
Thanks for the feedback. It is helpful. I will try to modify the approach. 👍🏻 |
Not really trivial and using I would avoid sleeping and just lower the number of batch requests in the next round by the number of 429s you get. PS are we testing this crate on WASM? If not PR fixing that before this one would be good. |
| Err(ureq::Error::Status(code, resp)) => { | ||
| if is_status_too_many_requests(code) { | ||
| eprintln!("Too many requests, sleeping for 500 ms"); | ||
| sleep(Duration::from_millis(500)); |
There was a problem hiding this comment.
this will cause a panic in wasm, might need to pass in a function that sleeps. for wasm sleep needs to be async too
|
I will try another approach in the EDIT: |
Closes bitcoindevkit/bdk#1120
Details
BlockingClient:scripthash_txsfor 429 Status codes.If detected, hard-coded sleep for 500ms using
std::thread::sleep(so it is also thread-safe).AsyncClient(little more convoluted thanBlockingClient):I had to bring
tokioandasync-recursioninto thedependencies.Inside the
scripthash_txswe are checking for 429 Status codes.If detected, hard-coded sleep for 500ms using
tokio::time::sleep.Since this is an "async recursion" the macro
async_recursionhandles that gracefully without having to deal with:If we annotate the offending recursive function with
#[async_recursion],it automatically convert an async function to one returning a boxed
Future.