vscode: Cannot send events as part of extension deactivation

If extensions send events as part of deactivate, awaiting disposal of the telemetry reporter exceeds the 4s shutdown limit for extensions, so these events aren’t sent.

Repro extension: repro.zip

extension.ts:

import * as vscode from 'vscode';
import * as fs from 'fs';
import TelemetryReporter from 'vscode-extension-telemetry';

let reporter: TelemetryReporter;
let sendEventOnDispose = true;

export function activate(context: vscode.ExtensionContext) {
	reporter = new TelemetryReporter('extension', '0.0.0', 'my-key');
}

export async function deactivate() {
	fs.writeFileSync('/start.txt', ''); 
	if (sendEventOnDispose) {
		reporter.sendTelemetryEvent('event');
	}
	await reporter.dispose();
	fs.writeFileSync('/end.txt', ''); 
}

If sendEventOnDispose is true, the extension never completes deactivating (end.txt isn’t created). If sendEventOnDispose is false, deactivation completes.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 20 (15 by maintainers)

Commits related to this issue

Most upvoted comments

The proxy support calls an Electron API on the main process to query for the proxy of a given URL. Maybe that doesn’t work during shutdown. There is a cache for the result, so unless the request is for a new hostname, that API should not be called. Thanks for the repro, I’ll need to investigate.

Yes, I can confirm that is the root problem. When I comment out the following in src/vs/workbench/api/node/extHostExtensionService.ts:

image

Then I get to see the await reporter.dispose(); returning.