Skip to content

Extension activation reports success before commands get registered #14773

@int19h

Description

@int19h

export async function activate(context: IExtensionContext): Promise<IExtensionApi> {
let api: IExtensionApi;
let ready: Promise<void>;
let serviceContainer: IServiceContainer;
try {
[api, ready, serviceContainer] = await activateUnsafe(context, stopWatch, durations);
} catch (ex) {
// We want to completely handle the error
// before notifying VS Code.
await handleError(ex, durations);
throw ex; // re-raise
}
// Send the "success" telemetry only if activation did not fail.
// Otherwise Telemetry is send via the error handler.
sendStartupTelemetry(ready, durations, stopWatch, serviceContainer)
// Run in the background.
.ignoreErrors();
return api;
}

Note that this code does not await ready. It does await the return value of activateUnsafe(), but that's not the same thing.

The effect is that when activate() returns, our command handlers might not actually be registered yet, and so if something tries to invoke them, it fails. One particular case where this can be consistently observed is our interaction with the Docker extension - in its debug configuration resolver, if the config is for Python, it uses VSCode API to activate vscode-python, and then assumes that it can return ${command:python.interpreterPath} in the config and have it properly expanded. But, because of the race condition, it often ends up as a blank string.

I believe the same is potentially possible with any command that we register under "activationEvents" in our manifest, since VSCode does essentially the same - activate(), then try to locate the command handler and execute it. This might be the root cause of #12072 and similar.

Metadata

Metadata

Assignees

Labels

area-editor-*User-facing catch-allbugIssue identified by VS Code Team member as probable bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions