Skip to content

fix(balance): stop polling the account endpoint once it 404s#742

Open
Danswar wants to merge 1 commit into
developfrom
fix/balance-stop-polling-on-404
Open

fix(balance): stop polling the account endpoint once it 404s#742
Danswar wants to merge 1 commit into
developfrom
fix/balance-stop-polling-on-404

Conversation

@Danswar

@Danswar Danswar commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Problem

BalanceService.startSync installs a 10s Timer.periodic that 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 — and updateBalance only acts on 200, 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 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 exist by then).

  • Gates the HTTP call rather than cancelling the timer — HomeBloc calls updateBalance(addr) (unawaited) immediately followed by startSync(addr), so cancelling the timer from inside updateBalance would race the just-started timer. A flag has no such race.
  • 200 still updates normally; transient 5xx are unaffected — only a definitive 404 (account genuinely absent) stops the poll.

Tests

Adds two fakeAsync cases to balance_service_test.dart:

  • after a 404, later ticks make no further network calls;
  • a fresh startSync resets 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 to BalanceService.

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.
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.

1 participant