Skip to content

Commit b64f931

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 bd5d777 commit b64f931

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
@@ -438,7 +438,7 @@ export class WatchingProblemCollector extends AbstractProblemCollector implement
438438
let markerChanged: IDisposable | undefined =
439439
Event.debounce(this.markerService.onMarkerChanged, (last: readonly URI[] | undefined, e: readonly URI[]) => {
440440
return (last ?? []).concat(e);
441-
}, 500)(async (markerEvent) => {
441+
}, 500, false, true)(async (markerEvent) => {
442442
markerChanged?.dispose();
443443
markerChanged = undefined;
444444
if (!markerEvent.includes(modelEvent.uri) || (this.markerService.read({ resource: modelEvent.uri }).length !== 0)) {
@@ -450,8 +450,11 @@ export class WatchingProblemCollector extends AbstractProblemCollector implement
450450
}
451451
});
452452
setTimeout(async () => {
453-
markerChanged?.dispose();
453+
// Calling dispose below can trigger the debounce event (via flushOnListenerRemove), so we
454+
// have to unset markerChanged first to make sure the handler above doesn't dispose it again.
455+
const _markerChanged = markerChanged;
454456
markerChanged = undefined;
457+
_markerChanged?.dispose();
455458
}, 600);
456459
}));
457460
}

0 commit comments

Comments
 (0)