Skip to content

Commit c7fb25d

Browse files
committed
check
1 parent 9a2c0e3 commit c7fb25d

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

src/main/osinstaller/CxInstaller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export class CxInstaller {
7171

7272
fs.chmodSync(this.getExecutablePath(), 0o755);
7373
logger.info('Extracted CLI to:', this.resourceDirPath);
74+
return Promise.resolve();
7475
} catch (error) {
7576
logger.error('Error during installation:', error);
7677
}

src/main/wrapper/CxWrapper.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import {Semaphore} from "async-mutex";
1111

1212

1313
type ParamTypeMap = Map<CxParamType, string>;
14-
const semaphore = new Semaphore(1); // Semaphore with 1 slot
15-
1614

1715
export class CxWrapper {
18-
private static instances =new Map<string, CxWrapper>(); // Multiton pattern
16+
private static instances = new Map<string, CxWrapper>(); // Multiton pattern
17+
private static semaphore = new Semaphore(1); // Semaphore with 1 slot
1918
config: CxConfig;
2019
cxInstaller: CxInstaller;
20+
2121
private constructor(cxScanConfig: CxConfig, logFilePath?: string) {
2222
this.cxInstaller = new CxInstaller(process.platform);
2323
this.config = new CxConfig();
@@ -51,27 +51,30 @@ export class CxWrapper {
5151
}
5252

5353
static async getInstance(cxScanConfig: CxConfig, logFilePath: string): Promise<CxWrapper> {
54-
const [, release] = await semaphore.acquire();
55-
const key = this.generateKey(cxScanConfig, logFilePath);
56-
let wrapper = CxWrapper.instances.get(key);
57-
if (!wrapper) {
58-
wrapper = new CxWrapper(cxScanConfig, logFilePath);
59-
CxWrapper.instances.set(key, wrapper);
60-
await wrapper.init();
54+
const [, release] = await this.semaphore.acquire();
55+
try {
56+
const key = this.generateKey(cxScanConfig, logFilePath);
57+
let wrapper = CxWrapper.instances.get(key);
58+
if (!wrapper) {
59+
wrapper = new CxWrapper(cxScanConfig, logFilePath);
60+
CxWrapper.instances.set(key, wrapper);
61+
await wrapper.init();
62+
}
63+
return wrapper;
64+
} finally {
65+
console.log(`Semaphore released by process: ${process.pid}`);
66+
release();
6167
}
62-
release();
63-
64-
return wrapper;
6568
}
66-
67-
static generateKey(config:CxConfig,logFilePath:string): string {
69+
70+
static generateKey(config: CxConfig, logFilePath: string): string {
6871
return `${config.baseUri}${config.baseAuthUri}${config.clientId}${config.clientSecret}${config.apiKey}${config.tenant}${config.additionalParameters}${config.pathToExecutable}${logFilePath}`.toLowerCase();
6972
}
7073

7174
async init(): Promise<void> {
7275
return await this.cxInstaller.downloadIfNotInstalledCLI();
7376
}
74-
77+
7578
public cloneWithNewConfig(scanConfig: CxConfig): CxWrapper {
7679
return new CxWrapper(scanConfig);
7780
}

0 commit comments

Comments
 (0)