Commit eb99805
committed
WORKSPACES-INIT (factory iter 2): clear _initPromise in try/finally so cache-reset triggers a real reload
bg/workspaces.js _init() guarded the cold-start race via _initPromise
but only cleared it on FAILURE (in the .catch handler). After a
successful init, _initPromise retained a resolved-promise reference
forever. Two concrete issues:
1. Memory: one orphan resolved-promise per WorkspaceManager instance
across the SW lifetime. Cosmetic.
2. Functional: a subsequent `this._cache = null` (factory reset,
test isolation) intends to force a fresh load on the next _init.
Pre-fix, the next _init hit `if (!this._initPromise) ...`,
found the stale resolved promise still cached, awaited it
(no-op since it was already settled), and returned WITHOUT
re-reading from chrome.storage.local. The cache stayed null —
subsequent reads crashed via `this._cache!.list`.
Fix: mirror the modules/storage.js init pattern — wrap the await in
try/finally that clears _initPromise on both success and failure.
async _init() {
if (this._cache !== null) return;
if (!this._initPromise) {
this._initPromise = (async () => { ... })();
}
try {
return await this._initPromise;
} finally {
this._initPromise = null;
}
}
3 new regression cases in tests/workspaces.test.js:
- clears _initPromise after successful init
- clears _initPromise after failed init
- null-ing _cache forces a real storage reload on the next _init
(would have failed on the pre-fix implementation)
45 test files, 769 cases green, tsc strict clean.1 parent f9dc4bd commit eb99805
2 files changed
Lines changed: 48 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
12 | 17 | | |
13 | 18 | | |
14 | 19 | | |
15 | 20 | | |
16 | 21 | | |
17 | 22 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
22 | 29 | | |
23 | | - | |
24 | 30 | | |
25 | 31 | | |
26 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
191 | 227 | | |
0 commit comments