test(gateway): stabilize session cleanup gates · openclaw/openclaw@30d9e70
steipete
·
2026-04-27
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -25,6 +25,10 @@ type HeldLock = {
|
25 | 25 | releasePromise?: Promise<void>; |
26 | 26 | }; |
27 | 27 | |
| 28 | +type SyncClosableFileHandle = fs.FileHandle & { |
| 29 | +[key: symbol]: unknown; |
| 30 | +}; |
| 31 | + |
28 | 32 | export type SessionLockInspection = { |
29 | 33 | lockPath: string; |
30 | 34 | pid: number | null; |
@@ -180,7 +184,7 @@ async function releaseHeldLock(
|
180 | 184 | */ |
181 | 185 | function releaseAllLocksSync(): void { |
182 | 186 | for (const [sessionFile, held] of HELD_LOCKS) { |
183 | | -void held.handle.close().catch(() => undefined); |
| 187 | +closeFileHandleSyncBestEffort(held.handle); |
184 | 188 | try { |
185 | 189 | fsSync.rmSync(held.lockPath, { force: true }); |
186 | 190 | } catch { |
@@ -193,6 +197,24 @@ function releaseAllLocksSync(): void {
|
193 | 197 | } |
194 | 198 | } |
195 | 199 | |
| 200 | +function closeFileHandleSyncBestEffort(handle: fs.FileHandle): void { |
| 201 | +const syncCloseSymbol = Object.getOwnPropertySymbols(Object.getPrototypeOf(handle)).find( |
| 202 | +(symbol) => symbol.description === "kCloseSync", |
| 203 | +); |
| 204 | +if (syncCloseSymbol) { |
| 205 | +const closeSync = (handle as SyncClosableFileHandle)[syncCloseSymbol]; |
| 206 | +if (typeof closeSync === "function") { |
| 207 | +try { |
| 208 | +closeSync.call(handle); |
| 209 | +return; |
| 210 | +} catch { |
| 211 | +// Fall back to async close below. |
| 212 | +} |
| 213 | +} |
| 214 | +} |
| 215 | +void handle.close().catch(() => undefined); |
| 216 | +} |
| 217 | + |
196 | 218 | async function runLockWatchdogCheck(nowMs = Date.now()): Promise<number> { |
197 | 219 | let released = 0; |
198 | 220 | for (const [sessionFile, held] of HELD_LOCKS.entries()) { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。