Skip to content

Commit

Permalink
acquire the mainLockFile asynchonrously
Browse files Browse the repository at this point in the history
  • Loading branch information
connor4312 committed Jul 22, 2021
1 parent 4a92332 commit 66b231d
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/vs/code/electron-main/main.ts
Expand Up @@ -59,7 +59,6 @@ import { cwd } from 'vs/base/common/process';
import { IProtocolMainService } from 'vs/platform/protocol/electron-main/protocol';
import { ProtocolMainService } from 'vs/platform/protocol/electron-main/protocolMainService';
import { Promises } from 'vs/base/common/async';
import { toDisposable } from 'vs/base/common/lifecycle';

/**
* The main VS Code entry point.
Expand Down Expand Up @@ -340,8 +339,7 @@ class CodeMain {
throw new ExpectedError('Sent env to running instance. Terminating...');
}

const lockFile = await this.createLockfile(environmentMainService);
once(lifecycleMainService.onWillShutdown)(() => lockFile.dispose());
this.createLockfile(logService, lifecycleMainService, environmentMainService);

// Print --status usage info
if (environmentMainService.args.status) {
Expand Down Expand Up @@ -423,10 +421,13 @@ class CodeMain {
lifecycleMainService.kill(exitCode);
}

private async createLockfile(env: IEnvironmentMainService) {
await FSPromises.writeFile(env.mainLockfile, String(process.pid));
private async createLockfile(logService: ILogService, lifecycle: ILifecycleMainService, env: IEnvironmentMainService) {
FSPromises.writeFile(env.mainLockfile, String(process.pid)).catch(err => {
logService.warn(`Error writing main lockfile: ${err.stack}`);
});


return toDisposable(() => {
once(lifecycle.onWillShutdown)(() => {
try {
unlinkSync(env.mainLockfile);
} catch {
Expand Down

1 comment on commit 66b231d

@bpasero
Copy link
Member

@bpasero bpasero commented on 66b231d Aug 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nits:

  • I prefer when methods declare their return type (createLockfile)
  • however, maybe this code should rather move up and inline to after this line because there we already have code that runs on lifecycleMainService.onWillShutdown so we could add the cleanup there too

Please sign in to comment.