Skip to content

Commit 08b8e5c

Browse files
IanMatthewHuffIan Huff
andauthored
Cache full ZMQ check promise, not just the result of the import (#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>
1 parent 782690d commit 08b8e5c

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

news/2 Fixes/12585.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Correctly check for ZMQ support, previously it could allow ZMQ to be supported when zmq could not be imported.

src/client/datascience/raw-kernel/rawNotebookSupportedService.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { IRawNotebookSupportedService } from '../types';
1313
@injectable()
1414
export class RawNotebookSupportedService implements IRawNotebookSupportedService {
1515
// Keep track of our ZMQ import check, this doesn't change with settings so we only want to do this once
16-
private _zmqSupported: boolean | undefined;
16+
private _zmqSupportedPromise: Promise<boolean> | undefined;
1717

1818
constructor(
1919
@inject(IConfigurationService) private readonly configuration: IConfigurationService,
@@ -48,21 +48,24 @@ export class RawNotebookSupportedService implements IRawNotebookSupportedService
4848

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

55+
return this._zmqSupportedPromise;
56+
}
57+
58+
private async zmqSupportedImpl(): Promise<boolean> {
5559
try {
5660
await import('zeromq');
5761
traceInfo(`ZMQ install verified.`);
5862
sendTelemetryEvent(Telemetry.ZMQSupported);
59-
this._zmqSupported = true;
6063
} catch (e) {
6164
traceError(`Exception while attempting zmq :`, e);
6265
sendTelemetryEvent(Telemetry.ZMQNotSupported);
63-
this._zmqSupported = false;
66+
return false;
6467
}
6568

66-
return this._zmqSupported;
69+
return true;
6770
}
6871
}

0 commit comments

Comments
 (0)