question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extension: During deactivate, globalState.update promises are immediately canceled

See original GitHub issue

Issue Type: Bug

Minimal repro here, which consists of the default yo code-created extension with the changes summarized below:

let globalState: vscode.Memento;

export function activate(context: vscode.ExtensionContext) {
  // ...
  globalState = context.globalState;
  console.log(`Pre-existing keys: [${globalState.keys().join(', ')}]`);
  globalState.update('test', 'repro');
}

export async function deactivate() {
  try {
    await globalState.update('test', undefined);
    console.log('globalState.update succeeded');
  } catch (err) {
    console.log(`globalState.update failed with ${err}`);
  }
}

Repro Steps

  1. Debug an extension (or install and run natively).
  2. Activate extension (in this case with Ctrl-Shift-P “Hello World”)
  3. Close VS Code
  4. In extension deactive, delete a key from context.globalState, and return the resulting promise.

Expected: As long as the promise finishes within 5 seconds, the operation will complete.

Actual: The promise is canceled. In the repro shown here, the message globalState.update failed with Canceled: Canceled is emitted. The next time the extension is run, the extension prints Pre-existing keys: [test], verifying that the key was not removed.

VS Code version: Code 1.64.2 (f80445acd5a3dadef24aa209168452a3d97cc326, 2022-02-09T22:02:28.252Z) OS version: Windows_NT x64 10.0.19044 Restricted Mode: No

System Info
Item Value
CPUs Intel® Core™ i7-8700K CPU @ 3.70GHz (12 x 3696)
GPU Status 2d_canvas: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
rasterization: enabled
skia_renderer: enabled_on
video_decode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 15.94GB (2.63GB free)
Process Argv –crash-reporter-id 1871b94c-c67d-43d1-b37d-bdf3332353ad
Screen Reader no
VM 0%
Extensions (35)
Extension Author (truncated) Version
tsl-problem-matcher amo 0.5.0
chronicler arc 0.1.16
doxdocgen csc 1.4.0
mustache daw 1.1.1
vscode-eslint dba 2.2.2
xml Dot 2.5.1
vscode-npm-script eg2 0.3.24
prettier-vscode esb 9.3.0
godot-javascript-debug gee 0.1.5
godot-tools gee 1.1.3
better-cpp-syntax jef 1.15.13
volar joh 0.32.0
hjson lak 0.3.2
template-string-converter meg 0.6.0
python ms- 2022.0.1814523869
vscode-pylance ms- 2022.2.4
jupyter-renderers ms- 1.0.6
remote-containers ms- 0.217.4
remote-ssh ms- 0.74.0
remote-ssh-edit ms- 0.74.0
remote-wsl ms- 0.64.2
vscode-remote-extensionpack ms- 0.21.0
cmake-tools ms- 1.9.2
cpptools ms- 1.8.4
cpptools-extension-pack ms- 1.1.0
live-server ms- 0.2.12
powershell ms- 2021.12.0
vscode-gn npc 1.1.0
vscode-versionlens pfl 1.0.9
svg-preview Sim 2.8.3
shader sle 1.1.5
es6-string-html Tob 2.12.0
cmake twx 0.0.17
sort-lines Tyr 1.9.1
wallaby-vscode Wal 1.0.327

(2 theme extensions excluded)

A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythonvspyl392:30443607
pythontb:30283811
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscorecescf:30442554
pythondataviewer:30285071
vscod805cf:30301675
pythonvspyt200:30340761
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593:30376534
vsc1dst:30438360
pythonvs932:30410667
wslgetstarted:30433507
vsclayoutctrt:30437039
vsrem710cf:30416617
vscop841cf:30438916
dsvsc008:30440022
pythonvsnew555:30442236
vsbas813:30436447
vscscmwlcmt:30438805
vscgsvidc:30438801
helix:30440343
vsnot107:30443614

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
gjsjohnmurraycommented, Mar 1, 2022

Related but probably a separate thread from all of this: I first started to implement cleanup tasks by returning Disposables from activate. Although dispose() is called at the same time as deactivate, Promises returned by dispose are not executed. That may be by design, but it is a little inconsistent. The dispose idiom also feels cleaner than passing state to deactivate via globals.

See https://github.com/microsoft/vscode/issues/140697#issuecomment-1017559485 and following.

0reactions
andreamahcommented, Aug 22, 2022

@andreamah this issue may be relevant to #128138 which you commented on and reopened today. I couldn’t add this comment there because when reopening it you forgot to unlock it.

oh, nice catch! thanks for letting me know!

Read more comments on GitHub >

github_iconTop Results From Across the Web

VS Code API | Visual Studio Code Extension API
VS Code API is a set of JavaScript APIs that you can invoke in your Visual Studio Code extension. This page lists all...
Read more >
vscode namespace API Reference
json to enable keybindings for your extension. Commands from other extensions and from the editor itself are accessible to an extension. However, when...
Read more >
Managing App State | Aurelia
The view directly binds to properties of the state. Actions can be dispatched and ... Take a look at the following upgrade instructions...
Read more >
The Complete Guide to React User Authentication with Auth0
You can now secure your React applications using security best practices while writing less code. ⚠️ This guide uses React Hooks and function ......
Read more >
NotificationListenerService - Android Developers
To extend this class, you must declare the service in your manifest file with the ... Notification was canceled due to an assistant...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found