urql: Retry-exchange Operations never resolving in react-native
urql version & exchanges:
"urql": "^2.0.3",
"@urql/exchange-retry": "^0.3.0",
"react-native": "~0.63.4"
"expo": "~41.0.1"
Steps to reproduce In react-native app:
- Setup queries to fail and be retried with
retryExhcnage - Fire off query
Expected behavior
Query retried maxNumberAttempts times and then resolves
Actual behavior
- Query never resolves (error never received by hook or manual caller)
- Retry query never fired (iOS + sometimes android)
Demo:
https://snack.expo.dev/@git/github.com/Mookiies/request-policy-demo-native
change expo to 41.0.0 in bottom bar

In this demo the toggle todos button will cause text to render when an error comes back from a useQuery and showing loading until then. It is common for it to get stuck in loading and never receive an error. This happens basically every time ios, sometimes android, never web (all same expo snack code).
Commenting out the retry exchange causes this problem to go away. When running locally with debugExchange you can see that operations stop passing between fetch and retry exchanges.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 23 (16 by maintainers)
I dove a bit deeper into this after your comment and started noticing that the
delayseemed to be causing this, removing it made the issue go away. I’ve attempted changing this to a static amount, 500 & 1000 but to no avail, it seems that the main issue is just thedelayfunction itself 😅 when looking at the implementation ofdelayI couldn’t find anything to explain this issue as it just leveragessetTimeoutHmm might be related:
@bryansum It’s nothing fancy I just took the code from the exchange here: https://github.com/FormidableLabs/urql/blob/main/exchanges/retry/src/retryExchange.ts and replaced the delay function on line 99 with a custom one using background timers. I copy-pasted the native js (compiled and optimized) function I found in
node_modules/wonka/dist/wonka.js.You could also look at the more “high level” one in
node_modules/wonka/src/web/WonkaJs.bs.jsalong with the type definition innode_modules/wonka/src/web/WonkaJs.gen.tsx, but that one has a dependency on a lib calledbs-platform.Here is the code I got
You can see the custom delay function on line 36 and where it is called on line 116 🙂
Yeh, the weird thing is this doesn’t seem to happen on web at all so I’m thinking it has something to do with how
setTimeout/ticksare handled in React-Native