fix: use mutex to prevent data race around electron singleton
Some checks failed
Playwright Tests / test (push) Failing after 2m0s

This commit is contained in:
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ 2026-02-11 18:58:12 -05:00
parent 8ed3faea13
commit 93d765d248
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C
3 changed files with 22 additions and 0 deletions

View File

@ -8,6 +8,7 @@
"@codemirror/view": "^6.0.1",
"@playwright/test": "^1.58.2",
"asar": "^3.2.0",
"async-mutex": "^0.5.0",
"electron": "^33.0.2",
"obsidian": "latest",
"playwright": "^1.58.2",

View File

@ -1,22 +1,26 @@
import type { ElectronApplication } from "playwright"
import {_electron as electron} from "playwright";
import { addConsoleListener } from "./internal-util.js";
import { Mutex } from "async-mutex";
const singleton: {
app: ElectronApplication | null
} = {
app: null,
}
const mutex = new Mutex();
export async function getOrCreateApp(obsidianPath: string, uriArg?: string) {
if (singleton.app) {
return singleton.app;
}
const release =await mutex.acquire();
const app = await electron.launch({
timeout: 60000,
args: [obsidianPath, uriArg].filter((a) => !!a) as string[],
});
addConsoleListener(app);
singleton.app = app;
await release();
return app;
}

View File

@ -1139,6 +1139,15 @@ __metadata:
languageName: node
linkType: hard
"async-mutex@npm:^0.5.0":
version: 0.5.0
resolution: "async-mutex@npm:0.5.0"
dependencies:
tslib: "npm:^2.4.0"
checksum: 10c0/9096e6ad6b674c894d8ddd5aa4c512b09bb05931b8746ebd634952b05685608b2b0820ed5c406e6569919ff5fe237ab3c491e6f2887d6da6b6ba906db3ee9c32
languageName: node
linkType: hard
"balanced-match@npm:^1.0.0":
version: 1.0.2
resolution: "balanced-match@npm:1.0.2"
@ -2626,6 +2635,7 @@ __metadata:
"@playwright/test": "npm:^1.58.2"
"@types/tmp": "npm:^0"
asar: "npm:^3.2.0"
async-mutex: "npm:^0.5.0"
electron: "npm:^33.0.2"
obsidian: "npm:latest"
playwright: "npm:^1.58.2"
@ -3284,6 +3294,13 @@ __metadata:
languageName: node
linkType: hard
"tslib@npm:^2.4.0":
version: 2.8.1
resolution: "tslib@npm:2.8.1"
checksum: 10c0/9c4759110a19c53f992d9aae23aac5ced636e99887b51b9e61def52611732872ff7668757d4e4c61f19691e36f4da981cd9485e869b4a7408d689f6bf1f14e62
languageName: node
linkType: hard
"tsutils@npm:^3.21.0":
version: 3.21.0
resolution: "tsutils@npm:3.21.0"