There is a race in task startup in terminalTaskService.ts #180541
Labels
bug
Issue identified by VS Code Team member as probable bug
insiders-released
Patch has been released in VS Code Insiders
tasks
Task system issues
verified
Verification succeeded
Milestone
Type: Bug
The race was reported in #159640 and partially fixed by #165560.
The fix doesn't fully cover the issue though. The problem is that the task identifier is added to
_inProgressTasks
just beforeterminalTaskSystem._executeTask()
is called, and removed just after. But_executeTask
will return (via "await") before updating_activeTasks
. So_activeTasks
won't be updated until the next tick (at the earliest, and possibly much much later).This is a problem because although terminalTaskSystem updates
_instances
immediately (so it knows how many instances of a task are running), it ignores that unless there's an entry in_activeTasks
.As a result, a task can be re-submitted after its name has been removed from
_inProgressTasks
, but before the first task has been added to_activeTasks
, bypass theinstanceLimit
check, and start a second, invalid instance. And this is the root cause of #159640.Typically the race can be hard to hit - especially after #165560 - but if the task has a "dependsOn" that runs for more than a few milliseconds, it's easy to repro. Use these commands to create and open a new project with a suitable task.
Trust the workspace, then hit Cmd-Shift-B three times in less than 2 seconds (but not too fast, or
_inProgressTasks
will stop the second and third attempts). You will get three instances of the task running.VS Code version: Code 1.77.3 (704ed70, 2023-04-12T09:19:37.325Z)
OS version: Darwin x64 22.4.0
Modes:
Sandboxed: No
System Info
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
Extensions (22)
A/B Experiments
The text was updated successfully, but these errors were encountered: