fix(balance): stop polling the account endpoint once it 404s#742
Open
Danswar wants to merge 1 commit into
Open
fix(balance): stop polling the account endpoint once it 404s#742Danswar wants to merge 1 commit into
Danswar wants to merge 1 commit into
Conversation
BalanceService.startSync runs a 10s Timer.periodic that GETs /v1/realunit/account/<address>. For a wallet with no RealUnit account the endpoint returns 404 on every tick, so the app hammers it indefinitely (~6 req/min/wallet) with no effect — updateBalance already ignored non-200, it just kept re-requesting. This shows up server-side as a steady stream of 404 'Account not found' responses. Mark the account missing on the first 404 and skip the network call on subsequent ticks. startSync resets the flag, so app resume / re-init / a post-onboarding restart re-checks (the account may now exist). Gating the HTTP call rather than cancelling the timer avoids racing the unawaited updateBalance + startSync pair in HomeBloc. 200 still updates normally; transient 5xx are unaffected (only a definitive 404 stops the poll). Adds tests: stops probing after a 404, and a fresh startSync re-checks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
BalanceService.startSyncinstalls a 10sTimer.periodicthat GETs/v1/realunit/account/<address>to refresh the RealUnit balance. For a wallet that has no RealUnit account, that endpoint returns 404"Account not found"on every tick — andupdateBalanceonly acts on200, so it silently keeps re-requesting forever (~6 req/min/wallet).Server-side (api.dfx.swiss) this is a steady stream of 404s that, because the response body contains
"error": "Not Found", gets logged and counted as errors — a recurring false "error spike" tracked back to this app.Fix
Mark the account missing on the first
404and skip the network call on subsequent ticks;startSyncresets the flag so app resume / re-init / a post-onboarding restart re-checks (the account may exist by then).HomeBloccallsupdateBalance(addr)(unawaited) immediately followed bystartSync(addr), so cancelling the timer from insideupdateBalancewould race the just-started timer. A flag has no such race.200still updates normally; transient 5xx are unaffected — only a definitive404(account genuinely absent) stops the poll.Tests
Adds two
fakeAsynccases tobalance_service_test.dart:startSyncresets the flag and re-probes (covers onboarding/resume).Note
I don't have a local Flutter toolchain, so I relied on the existing test patterns — please let CI (
flutter analyze+flutter test) confirm. The change is confined toBalanceService.