Skip to content

Commit

Permalink
Fix race condition with restoration of problems when closing a file
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
russelldavis committed Jun 9, 2023
1 parent 5b55835 commit a3c4a35
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/vs/workbench/contrib/tasks/common/problemCollectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ export class WatchingProblemCollector extends AbstractProblemCollector implement
let markerChanged: IDisposable | undefined =
Event.debounce(this.markerService.onMarkerChanged, (last: readonly URI[] | undefined, e: readonly URI[]) => {
return (last ?? []).concat(e);
}, 500)(async (markerEvent) => {
}, 500, false, true)(async (markerEvent) => {
markerChanged?.dispose();
markerChanged = undefined;
if (!markerEvent.includes(modelEvent.uri) || (this.markerService.read({ resource: modelEvent.uri }).length !== 0)) {
Expand All @@ -448,8 +448,11 @@ export class WatchingProblemCollector extends AbstractProblemCollector implement
}
});
setTimeout(async () => {
markerChanged?.dispose();
// Calling dispose below can trigger the debounce event (via flushOnListenerRemove), so we
// have to unset markerChanged first to make sure the handler above doesn't dispose it again.
const _markerChanged = markerChanged;
markerChanged = undefined;
_markerChanged?.dispose();
}, 600);
}));
}
Expand Down

0 comments on commit a3c4a35

Please sign in to comment.