gsd-pi 2.31.0-dev.6ffc032 → 2.31.0
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.
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { clearLock } from "./crash-recovery.js";
|
|
8
|
-
import { releaseSessionLock } from "./session-lock.js";
|
|
9
8
|
import { nativeHasChanges } from "./native-git-bridge.js";
|
|
10
9
|
|
|
11
10
|
// ─── SIGTERM Handling ─────────────────────────────────────────────────────────
|
|
@@ -24,7 +23,6 @@ export function registerSigtermHandler(
|
|
|
24
23
|
): () => void {
|
|
25
24
|
if (previousHandler) process.off("SIGTERM", previousHandler);
|
|
26
25
|
const handler = () => {
|
|
27
|
-
releaseSessionLock(currentBasePath);
|
|
28
26
|
clearLock(currentBasePath);
|
|
29
27
|
process.exit(0);
|
|
30
28
|
};
|
|
@@ -51,9 +51,6 @@ let _lockedPath: string | null = null;
|
|
|
51
51
|
/** Our PID at lock acquisition time. */
|
|
52
52
|
let _lockPid: number = 0;
|
|
53
53
|
|
|
54
|
-
/** Set to true when proper-lockfile fires onCompromised (mtime drift, sleep, etc.). */
|
|
55
|
-
let _lockCompromised: boolean = false;
|
|
56
|
-
|
|
57
54
|
const LOCK_FILE = "auto.lock";
|
|
58
55
|
|
|
59
56
|
function lockPath(basePath: string): string {
|
|
@@ -105,22 +102,13 @@ export function acquireSessionLock(basePath: string): SessionLockResult {
|
|
|
105
102
|
|
|
106
103
|
const release = lockfile.lockSync(gsdDir, {
|
|
107
104
|
realpath: false,
|
|
108
|
-
stale:
|
|
105
|
+
stale: 300_000, // 5 minutes — consider lock stale if holder hasn't updated
|
|
109
106
|
update: 10_000, // Update lock mtime every 10s to prove liveness
|
|
110
|
-
onCompromised: () => {
|
|
111
|
-
// proper-lockfile detected mtime drift (system sleep, event loop stall, etc.).
|
|
112
|
-
// Default handler throws inside setTimeout — an uncaught exception that crashes
|
|
113
|
-
// or corrupts process state. Instead, set a flag so validateSessionLock() can
|
|
114
|
-
// detect the compromise gracefully on the next dispatch cycle.
|
|
115
|
-
_lockCompromised = true;
|
|
116
|
-
_releaseFunction = null;
|
|
117
|
-
},
|
|
118
107
|
});
|
|
119
108
|
|
|
120
109
|
_releaseFunction = release;
|
|
121
110
|
_lockedPath = basePath;
|
|
122
111
|
_lockPid = process.pid;
|
|
123
|
-
_lockCompromised = false;
|
|
124
112
|
|
|
125
113
|
// Safety net: clean up lock dir on process exit if _releaseFunction
|
|
126
114
|
// wasn't called (e.g., normal exit after clean completion) (#1245).
|
|
@@ -245,11 +233,6 @@ export function updateSessionLock(
|
|
|
245
233
|
* This is called periodically during the dispatch loop.
|
|
246
234
|
*/
|
|
247
235
|
export function validateSessionLock(basePath: string): boolean {
|
|
248
|
-
// Lock was compromised by proper-lockfile (mtime drift from sleep, stall, etc.)
|
|
249
|
-
if (_lockCompromised) {
|
|
250
|
-
return false;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
236
|
// If we have an OS-level lock, we're still the owner
|
|
254
237
|
if (_releaseFunction && _lockedPath === basePath) {
|
|
255
238
|
return true;
|
|
@@ -301,7 +284,6 @@ export function releaseSessionLock(basePath: string): void {
|
|
|
301
284
|
|
|
302
285
|
_lockedPath = null;
|
|
303
286
|
_lockPid = 0;
|
|
304
|
-
_lockCompromised = false;
|
|
305
287
|
}
|
|
306
288
|
|
|
307
289
|
/**
|
package/package.json
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { clearLock } from "./crash-recovery.js";
|
|
8
|
-
import { releaseSessionLock } from "./session-lock.js";
|
|
9
8
|
import { nativeHasChanges } from "./native-git-bridge.js";
|
|
10
9
|
|
|
11
10
|
// ─── SIGTERM Handling ─────────────────────────────────────────────────────────
|
|
@@ -24,7 +23,6 @@ export function registerSigtermHandler(
|
|
|
24
23
|
): () => void {
|
|
25
24
|
if (previousHandler) process.off("SIGTERM", previousHandler);
|
|
26
25
|
const handler = () => {
|
|
27
|
-
releaseSessionLock(currentBasePath);
|
|
28
26
|
clearLock(currentBasePath);
|
|
29
27
|
process.exit(0);
|
|
30
28
|
};
|
|
@@ -51,9 +51,6 @@ let _lockedPath: string | null = null;
|
|
|
51
51
|
/** Our PID at lock acquisition time. */
|
|
52
52
|
let _lockPid: number = 0;
|
|
53
53
|
|
|
54
|
-
/** Set to true when proper-lockfile fires onCompromised (mtime drift, sleep, etc.). */
|
|
55
|
-
let _lockCompromised: boolean = false;
|
|
56
|
-
|
|
57
54
|
const LOCK_FILE = "auto.lock";
|
|
58
55
|
|
|
59
56
|
function lockPath(basePath: string): string {
|
|
@@ -105,22 +102,13 @@ export function acquireSessionLock(basePath: string): SessionLockResult {
|
|
|
105
102
|
|
|
106
103
|
const release = lockfile.lockSync(gsdDir, {
|
|
107
104
|
realpath: false,
|
|
108
|
-
stale:
|
|
105
|
+
stale: 300_000, // 5 minutes — consider lock stale if holder hasn't updated
|
|
109
106
|
update: 10_000, // Update lock mtime every 10s to prove liveness
|
|
110
|
-
onCompromised: () => {
|
|
111
|
-
// proper-lockfile detected mtime drift (system sleep, event loop stall, etc.).
|
|
112
|
-
// Default handler throws inside setTimeout — an uncaught exception that crashes
|
|
113
|
-
// or corrupts process state. Instead, set a flag so validateSessionLock() can
|
|
114
|
-
// detect the compromise gracefully on the next dispatch cycle.
|
|
115
|
-
_lockCompromised = true;
|
|
116
|
-
_releaseFunction = null;
|
|
117
|
-
},
|
|
118
107
|
});
|
|
119
108
|
|
|
120
109
|
_releaseFunction = release;
|
|
121
110
|
_lockedPath = basePath;
|
|
122
111
|
_lockPid = process.pid;
|
|
123
|
-
_lockCompromised = false;
|
|
124
112
|
|
|
125
113
|
// Safety net: clean up lock dir on process exit if _releaseFunction
|
|
126
114
|
// wasn't called (e.g., normal exit after clean completion) (#1245).
|
|
@@ -245,11 +233,6 @@ export function updateSessionLock(
|
|
|
245
233
|
* This is called periodically during the dispatch loop.
|
|
246
234
|
*/
|
|
247
235
|
export function validateSessionLock(basePath: string): boolean {
|
|
248
|
-
// Lock was compromised by proper-lockfile (mtime drift from sleep, stall, etc.)
|
|
249
|
-
if (_lockCompromised) {
|
|
250
|
-
return false;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
236
|
// If we have an OS-level lock, we're still the owner
|
|
254
237
|
if (_releaseFunction && _lockedPath === basePath) {
|
|
255
238
|
return true;
|
|
@@ -301,7 +284,6 @@ export function releaseSessionLock(basePath: string): void {
|
|
|
301
284
|
|
|
302
285
|
_lockedPath = null;
|
|
303
286
|
_lockPid = 0;
|
|
304
|
-
_lockCompromised = false;
|
|
305
287
|
}
|
|
306
288
|
|
|
307
289
|
/**
|