Skip to content

Commit a3c4a35

Browse files
committed
Fix race condition with restoration of problems when closing a file
Fixes microsoft#47386 This sets the `flushOnListenerRemove` option to true for the call to Event.debounce. Without this, some `onMarkerChanged` events can get dropped -- specifically, when an event gets fired more than 100ms after first listening, in which case the 600ms cleanup setTimeout fires while the 500ms debounce timeout is still pending.
1 parent 5b55835 commit a3c4a35

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/vs/workbench/contrib/tasks/common/problemCollectors.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ export class WatchingProblemCollector extends AbstractProblemCollector implement
436436
let markerChanged: IDisposable | undefined =
437437
Event.debounce(this.markerService.onMarkerChanged, (last: readonly URI[] | undefined, e: readonly URI[]) => {
438438
return (last ?? []).concat(e);
439-
}, 500)(async (markerEvent) => {
439+
}, 500, false, true)(async (markerEvent) => {
440440
markerChanged?.dispose();
441441
markerChanged = undefined;
442442
if (!markerEvent.includes(modelEvent.uri) || (this.markerService.read({ resource: modelEvent.uri }).length !== 0)) {
@@ -448,8 +448,11 @@ export class WatchingProblemCollector extends AbstractProblemCollector implement
448448
}
449449
});
450450
setTimeout(async () => {
451-
markerChanged?.dispose();
451+
// Calling dispose below can trigger the debounce event (via flushOnListenerRemove), so we
452+
// have to unset markerChanged first to make sure the handler above doesn't dispose it again.
453+
const _markerChanged = markerChanged;
452454
markerChanged = undefined;
455+
_markerChanged?.dispose();
453456
}, 600);
454457
}));
455458
}

0 commit comments

Comments
 (0)