Repository navigation
Commit ab70702
committed
fix(config): single-flight the reset so an overlapping caller cannot lower the guard early
resetAllState() had one guard and no owner. Two overlapping calls each ran their own delete pass, and the
pass that finished first lowered the reset flag while the other was still inside its deletes, so a secret
write that landed in that window was refused even though a reset was still erasing state - and, on the
other side, a write that landed inside the still-running pass was erased by it. The finally added in the
parent commit guarantees the flag falls when the pass it belongs to ends; it does not say which pass that
is, and with two passes neither guarantee is worth much.
Single-flight rather than the depth counter the reviewer proposed: a second caller joins the pass already
running instead of starting one, so there is exactly one reset pass at a time and the flag cannot fall
while a pass is in flight by construction rather than by arithmetic. A counter needs every entry to be
matched by an exit on every path, including the throwing ones, and that is a claim about the code shape
rather than about the state, which is the thing the row is about.
resetAllState() drops the async keyword and returns the stored promise. That is not cosmetic: an async
function hands every caller a fresh promise object, so a joined caller is indistinguishable from a second
caller and the invariant cannot be observed, let alone asserted. Behaviourally the change is that a caller
which arrives mid-reset now waits for a reset it did not start, and a caller that arrives after a pass
settles starts a fresh one: the slot is cleared in the same finally that lowers the guard.
Test: joins an in-flight reset instead of starting a second pass and keeps the guard raised until it ends.
The erase double keeps a rejecter for every apiKey erase it hands back and settles them all at once, so
the pass cannot hang on an erase nobody rejects; the test yields one macrotask before counting because
the reset awaits its pending-write barrier before it reaches the delete pass, and apiKey is erased exactly
once per pass - SECRET_STATE_KEYS in packages/types/src/global-settings.ts:361 lists it once and
GLOBAL_SECRET_KEYS at :401 does not list it - so one erase is the measurement of one pass.
Controls. Concurrency case first: with the parent commit's ContextProxy.ts in place it fails with
Tests 1 failed | 317 passed (318) and the message is the defect - AssertionError: expected Promise{...} to
be Promise{...} // Object.is equality - a second caller with a pass of its own. With single-flight:
Test Files 10 passed (10), Tests 318 passed (318). Nothing existing had to move: core/config went 316 to
318 by the two cases added here and its parent, and core/webview is 34 files / 956 tests passed, identical
to the same tree without these commits, so no ordering test disagreed with single-flight and none was
bent. tsc -p . --noEmit exit 0, eslint --max-warnings=0 exit 0 on both files, and with
--prune-suppressions the recorded counts for the two touched files stay 1 and 5, unchanged.
Mutation posture: 44 added / 31 deleted lines in one executable file on a unit already measured over the
500 changed-executable-line cap against upstream main (539 for this PR head at scripts/stryker-diff.mjs),
so this commit adds to an overrun that exists without it; the spec half is excluded by the /__tests__/
segment at scripts/stryker-diff.mjs:85.
Review row answered: #2227 ContextProxy.ts:751 (root comment 4479544520), second half - overlapping
resetAllState calls.1 parent 32d9a10 commit ab70702
2 files changed
Lines changed: 87 additions & 31 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
410 | 410 | | |
411 | 411 | | |
412 | 412 | | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
413 | 416 | | |
414 | 417 | | |
415 | 418 | | |
| |||
747 | 750 | | |
748 | 751 | | |
749 | 752 | | |
750 | | - | |
751 | | - | |
752 | | - | |
753 | | - | |
754 | | - | |
755 | | - | |
756 | | - | |
757 | | - | |
758 | | - | |
759 | | - | |
760 | | - | |
761 | | - | |
762 | | - | |
763 | | - | |
764 | | - | |
765 | | - | |
766 | | - | |
767 | | - | |
768 | | - | |
769 | | - | |
770 | | - | |
771 | | - | |
772 | | - | |
773 | | - | |
774 | | - | |
775 | | - | |
776 | | - | |
777 | | - | |
778 | | - | |
779 | | - | |
780 | | - | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
781 | 758 | | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
782 | 795 | | |
783 | 796 | | |
784 | 797 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
235 | 278 | | |
236 | 279 | | |
237 | 280 | | |
| |||
0 commit comments