vscode: macOS: Unable to quit when all windows are closed

Type: Bug

VS Code has trouble quitting with the cmd+Q shortcut on macOS. When I use cmd+Q quickly after cmd+shift+W, VS Code hangs and remains open. I can tell that VS Code is open by the indicator dot under its icon in the dock.

Steps to reproduce:

  1. Open VS Code on macOS
  2. Use cmd+shift+W to close all windows
  3. Quickly use cmd+Q to quit VS Code
  4. Notice that the “Code” title in the macOS menubar flashes
  5. Notice the dot under VS Code’s icon in the dock and that VS Code remains open

I’ve seen this bug in both VS Code stable and insiders.

Here’s a screen recording of this bug:

https://user-images.githubusercontent.com/19893438/215887767-4a78d24c-8c30-4344-b56a-f0061edbbad7.mp4

Notice how the “Code” title in the menubar flashes as the windows close. It seems like VS Code is receivng the quit event, but it’s getting stuck somewhere.

VS Code version: Code 1.74.3 (97dec172d3256f8ca4bfb2143f3f76b503ca0534, 2023-01-09T17:05:47.808Z) OS version: Darwin arm64 21.6.0 Modes: Sandboxed: No

System Info
Item Value
CPUs Apple M1 Max (10 x 24)
GPU Status 2d_canvas: enabled
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
Load (avg) 2, 2, 2
Memory (System) 64.00GB (36.59GB free)
Process Argv –crash-reporter-id 3488aeac-bc57-46d3-ac1a-73d78d4582d6
Screen Reader no
VM 0%
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263cf:30335440
vscoreces:30445986
pythondataviewer:30285071
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593cf:30376535
pythonvs932:30410667
cppdebug:30492333
vscaat:30438848
vsclangdf:30486550
c4g48928:30535728
dsvsc012cf:30540253
azure-dev_surveyone:30548225
pyindex848:30577860
nodejswelcome1:30587005
2e4cg342:30602488
pyind779:30647091
89544117:30613380
2i9eh265:30646982

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 4
  • Comments: 60 (29 by maintainers)

Commits related to this issue

Most upvoted comments

You two may ask yourselves, “How did he try it 120 times in a row?”

Good news, I figured out a way to consistently repro this bug! I wrote a script that opens VS Code, sends the cmd+shift+W shortcut to close all windows, sends a quit event, and checks if VS Code is still running. Check it out:

https://user-images.githubusercontent.com/19893438/219523168-ab6d789c-f5e7-4cf7-bcae-6fa545b4a9b4.mp4

Here are the results for our two telemetry cases:

Disabling telemetry fully eliminates the bug.

GitHub won’t let me share the .scpt file, but you can use Script Editor on macOS to run it: measure-code.txt

  1. Download measure-code.txt
  2. Open Script Editor
  3. Copy and paste the script into the editor
  4. Show the log view
  5. Switch to the Messages tab Messages tab in log view
  6. Run the script

If you run into a permissions issue regarding accessibility and sending keystrokes, then you need to follow the prompt and open System Preferences to give Script Editor accessibility permissions.

Same here. I can’t reproduce the issue with the latest Insiders build.

@jungaretti @klaussner can you start the application with the following arguments --trace --trace-category-filter="browser,io,ipc,net,mojom,renderer_host,shutdown,disabled-by-default-lifecycles,disabled-by-default-network", perform the steps below,

  1. Close all open windows Ctrl + Shift.+ W
  2. Quit the application Cmd + Q
  3. As per the bug, application should still hang around in the dock
  4. Open a new window from this running instance
  5. Open command paletter Cmd + Shift + P and run Developer: Stop Tracing
  6. Attach the generated trace in this issue thread.

Do people that see this have any special firewall enabled or network monitor?

I tested it on two different devices in two locations/networks (without a VPN or firewall) and couldn’t see a difference.

Can you try the following settings to confirm if the issue persists, thanks!

The issue persists with these settings. 🙁


I don’t know if it helps, but if you monitor the requests sent to the telemetry endpoint with mitmproxy, you can see that the final requests are handled differently, depending on the timing:

  • If the app doesn’t quit, requests are sent (and responses are received) after <kbd>⌘</kbd>+<kbd>Q</kbd> (first part of the video).
  • If the app quits, the final request is aborted immediately (second part of the video).

https://user-images.githubusercontent.com/1312807/220744568-ab558843-d068-4b5b-a6ad-bc7ee1f62160.mp4

Do people that see this have any special firewall enabled or network monitor?

I don’t think so. I use a VPN at home and work, but I can repro the bug when that is turned off.

Great idea to use a script for reproduction, @jungaretti! After tweaking a few values (warmupDelay = 1.5 and minQuitDelay = 0.5) and adding tell application code to quit at the beginning of testCode (to close the app in case quitting failed during the last call), I could confirm that the problem was introduced in the Insiders build for commit bc0bdc5d0969030f114d5931b18e134059da00c1 from July 7, 2022:

https://user-images.githubusercontent.com/1312807/219703186-e485a72a-5a63-4dd8-bed9-0bf28c94bef8.mp4

Disabling telemetry with "telemetry.telemetryLevel": "off" fully resolved the issue for me. I tried 120 times in a row and didn’t see the bug at all. Nice find @klaussner, you’re a legend!

After looking into it further, I’m pretty sure that this issue is related to telemetry (which would explain why I couldn’t reproduce it with the OSS build). If telemetry is disabled with "telemetry.telemetryLevel": "off", VS Code always quits as expected.

To track down where the problem was introduced, I binary searched through Insiders builds released between January 2022 (where I found a working version) and today. This is the result:

The changes between these two versions include a few changes to telemetry, but I’m not familiar enough with VS Code internals to find out what exactly causes the problem.

I’m able to repro with the steps from @klaussner’s recording. Here are my logs and another recording:

vscode-not-quitting-clicks.txt

https://user-images.githubusercontent.com/19893438/216132775-7b0e71fc-b825-45c9-b162-194ebf7b6f91.mp4

Here’s another screen recording in case it helps.

  • The time between closing the window and quitting the application doesn’t seem to matter.
  • After quitting, you can click on the app icon to open another window, but the menu is missing several items.
  • Closing the new window immediately quits the application.

https://user-images.githubusercontent.com/1312807/216125156-8a5991b7-65cc-4aa9-809b-971a5d5b1bac.mp4

All of my screen recordings show cmd+shift+W followed by cmd+Q. That’s my daily flow and I encounter this bug most when following it. Sorry if that wasn’t clear.

cmd+Q alone feels more reliable than cmd+shift+W followed by cmd+Q. Here are the logs from using just cmd+Q where VS Code quits properly:

quit-success.txt

These logs look different than the failure logs. I don’t see closed application storage in the logs where VS Code didn’t quit properly.