gm-plugkit 2.0.1576 → 2.0.1577
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/plugkit-wasm-wrapper.js +25 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gm-plugkit",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1577",
|
|
4
4
|
"description": "Bootstrap and daemon-spawn tool for gm plugkit binary. Downloads the correct platform binary, verifies SHA256, and starts the spool watcher daemon. Includes plugkit-wasm-wrapper for WASM-based spool watching.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
package/plugkit-wasm-wrapper.js
CHANGED
|
@@ -2139,8 +2139,8 @@ async function runSpoolWatcher(instance, spoolDir) {
|
|
|
2139
2139
|
}
|
|
2140
2140
|
function lockBody() { return `${process.pid}|${Date.now()}|${_ownWrapperSha12}`; }
|
|
2141
2141
|
function acquireLock() {
|
|
2142
|
-
|
|
2143
|
-
|
|
2142
|
+
function checkExistingHolder() {
|
|
2143
|
+
try {
|
|
2144
2144
|
const content = fs.readFileSync(LOCK_PATH, 'utf-8').trim();
|
|
2145
2145
|
const parts = content.split('|');
|
|
2146
2146
|
const pidStr = parts[0];
|
|
@@ -2164,6 +2164,7 @@ async function runSpoolWatcher(instance, spoolDir) {
|
|
|
2164
2164
|
}));
|
|
2165
2165
|
} catch (_) {}
|
|
2166
2166
|
try { process.kill(parseInt(pidStr, 10), 'SIGTERM'); } catch (_) {}
|
|
2167
|
+
return 'takeover';
|
|
2167
2168
|
} else {
|
|
2168
2169
|
const msg = JSON.stringify({ ok: false, reason: 'another-watcher-active', pid: pidStr, age_ms: age });
|
|
2169
2170
|
console.error(`[plugkit-wasm] ${msg}; refusing to start`);
|
|
@@ -2181,11 +2182,32 @@ async function runSpoolWatcher(instance, spoolDir) {
|
|
|
2181
2182
|
} else if (!holderAlive) {
|
|
2182
2183
|
console.error(`[plugkit-wasm] stale lock (holder pid=${pidStr} dead, age=${age}ms); taking over`);
|
|
2183
2184
|
try { logEvent('plugkit', 'watcher.lock-pid-dead-takeover', { stale_pid: pidStr, lock_age_ms: age }); } catch (_) {}
|
|
2185
|
+
return 'takeover';
|
|
2184
2186
|
} else {
|
|
2185
2187
|
console.error(`[plugkit-wasm] stale lock (age=${age}ms); taking over`);
|
|
2188
|
+
return 'takeover';
|
|
2186
2189
|
}
|
|
2190
|
+
} catch (_) {
|
|
2191
|
+
return 'takeover';
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
try {
|
|
2195
|
+
let fd;
|
|
2196
|
+
try {
|
|
2197
|
+
fd = fs.openSync(LOCK_PATH, 'wx');
|
|
2198
|
+
} catch (e) {
|
|
2199
|
+
if (e.code !== 'EEXIST') throw e;
|
|
2200
|
+
const action = checkExistingHolder();
|
|
2201
|
+
if (action !== 'takeover') return;
|
|
2202
|
+
try { fs.unlinkSync(LOCK_PATH); } catch (_) {}
|
|
2203
|
+
fd = fs.openSync(LOCK_PATH, 'wx');
|
|
2204
|
+
}
|
|
2205
|
+
try {
|
|
2206
|
+
const body = Buffer.from(lockBody(), 'utf-8');
|
|
2207
|
+
fs.writeSync(fd, body);
|
|
2208
|
+
} finally {
|
|
2209
|
+
fs.closeSync(fd);
|
|
2187
2210
|
}
|
|
2188
|
-
fs.writeFileSync(LOCK_PATH, lockBody());
|
|
2189
2211
|
} catch (e) {
|
|
2190
2212
|
console.error(`[plugkit-wasm] lock acquire failed: ${e.message}`);
|
|
2191
2213
|
process.exit(1);
|