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:
- Open VS Code on macOS
- Use
cmd+shift+Wto close all windows - Quickly use
cmd+Qto quit VS Code - Notice that the “Code” title in the macOS menubar flashes
- 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:
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
- add more logging for #172967 — committed to microsoft/vscode by bpasero a year ago
- add more logging for #172967 (#173833) — committed to microsoft/vscode by bpasero a year ago
- add more logging for #172967 (#173833) — committed to c-claeys/vscode by bpasero a year ago
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+Wshortcut 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
.scptfile, but you can useScript Editoron macOS to run it: measure-code.txtScript EditorMessagestabIf you run into a permissions issue regarding accessibility and sending keystrokes, then you need to follow the prompt and open
System Preferencesto giveScript Editoraccessibility 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,Ctrl + Shift.+ WCmd + QCmd + Shift + Pand runDeveloper: Stop TracingI tested it on two different devices in two locations/networks (without a VPN or firewall) and couldn’t see a difference.
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:https://user-images.githubusercontent.com/1312807/220744568-ab558843-d068-4b5b-a6ad-bc7ee1f62160.mp4
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.5andminQuitDelay = 0.5) and addingtell application code to quitat the beginning oftestCode(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.
https://user-images.githubusercontent.com/1312807/216125156-8a5991b7-65cc-4aa9-809b-971a5d5b1bac.mp4
All of my screen recordings show
cmd+shift+Wfollowed bycmd+Q. That’s my daily flow and I encounter this bug most when following it. Sorry if that wasn’t clear.cmd+Qalone feels more reliable thancmd+shift+Wfollowed bycmd+Q. Here are the logs from using justcmd+Qwhere VS Code quits properly:quit-success.txt
These logs look different than the failure logs. I don’t see
closed application storagein the logs where VS Code didn’t quit properly.