Skip to content

Commit 13aecdd

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 a4bbb63 commit 13aecdd

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
@@ -124,10 +124,13 @@ abstract class GlobalStore extends ChangeNotifier {
124124
// It's up to us. Start loading.
125125
future = loadPerAccount(accountId);
126126
_perAccountStoresLoading[accountId] = future;
127-
store = await future;
128-
_setPerAccount(accountId, store);
129-
unawaited(_perAccountStoresLoading.remove(accountId));
130-
return store;
127+
try {
128+
store = await future;
129+
_setPerAccount(accountId, store);
130+
return store;
131+
} finally {
132+
unawaited(_perAccountStoresLoading.remove(accountId));
133+
}
131134
}
132135

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

0 commit comments

Comments
 (0)