Skip to content

Commit

Permalink
Cache full ZMQ check promise, not just the result of the import (micr…
Browse files Browse the repository at this point in the history
…osoft#12610)

* save ZMQ support check in a promise to prevent race condition

* remove old comment

Co-authored-by: Ian Huff <ianhuff@BE-ADINAB-SB2.europe.corp.microsoft.com>
  • Loading branch information
IanMatthewHuff and Ian Huff committed Jun 29, 2020
1 parent 782690d commit 08b8e5c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions news/2 Fixes/12585.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Correctly check for ZMQ support, previously it could allow ZMQ to be supported when zmq could not be imported.
15 changes: 9 additions & 6 deletions src/client/datascience/raw-kernel/rawNotebookSupportedService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { IRawNotebookSupportedService } from '../types';
@injectable()
export class RawNotebookSupportedService implements IRawNotebookSupportedService {
// Keep track of our ZMQ import check, this doesn't change with settings so we only want to do this once
private _zmqSupported: boolean | undefined;
private _zmqSupportedPromise: Promise<boolean> | undefined;

constructor(
@inject(IConfigurationService) private readonly configuration: IConfigurationService,
Expand Down Expand Up @@ -48,21 +48,24 @@ export class RawNotebookSupportedService implements IRawNotebookSupportedService

// Check to see if this machine supports our local ZMQ launching
private async zmqSupported(): Promise<boolean> {
if (this._zmqSupported !== undefined) {
return this._zmqSupported;
if (!this._zmqSupportedPromise) {
this._zmqSupportedPromise = this.zmqSupportedImpl();
}

return this._zmqSupportedPromise;
}

private async zmqSupportedImpl(): Promise<boolean> {
try {
await import('zeromq');
traceInfo(`ZMQ install verified.`);
sendTelemetryEvent(Telemetry.ZMQSupported);
this._zmqSupported = true;
} catch (e) {
traceError(`Exception while attempting zmq :`, e);
sendTelemetryEvent(Telemetry.ZMQNotSupported);
this._zmqSupported = false;
return false;
}

return this._zmqSupported;
return true;
}
}

0 comments on commit 08b8e5c

Please sign in to comment.