Skip to content

Commit 7075045

Browse files
committed
store [nfc]: Use try/finally to clear _perAccountStoresLoading[accountId]
In GlobalStore.perAccount, the loadPerAccount future can throw, and in that case the `_perAccountStoresLoading.remove` in these lines of code hasn't been getting called. That's only a latent bug, currently, because loadPerAccount only throws if the account was logged out, and we always do a `_perAccountStoresLoading.remove` on logout (in GlobalStore.removeAccount). But we'd like to add another case where the loadPerAccount future throws (disallow connecting to ancient servers), which doesn't involve logout / removeAccount. So this try/finally will be important for that case.
1 parent 0a2273c commit 7075045

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/model/store.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,13 @@ abstract class GlobalStore extends ChangeNotifier {
147147
// It's up to us. Start loading.
148148
future = loadPerAccount(accountId);
149149
_perAccountStoresLoading[accountId] = future;
150-
store = await future;
151-
_setPerAccount(accountId, store);
152-
unawaited(_perAccountStoresLoading.remove(accountId));
153-
return store;
150+
try {
151+
store = await future;
152+
_setPerAccount(accountId, store);
153+
return store;
154+
} finally {
155+
unawaited(_perAccountStoresLoading.remove(accountId));
156+
}
154157
}
155158

156159
Future<void> _reloadPerAccount(int accountId) async {

0 commit comments

Comments
 (0)