openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.07 kB
JavaScript
import{s as raceWithTimeout}from"./runtime-process-manifest-CzeI_ZiX.js";import{a as runtimeProcessEntrypoints}from"./runtime-binary-BWC3z4wd.js";import{r as resolveRuntimeWorkerUrl}from"./runtime-worker-url-C_8irENp.js";import{join}from"node:path";import{mkdtemp,realpath,rm}from"node:fs/promises";import{tmpdir}from"node:os";import{Worker}from"node:worker_threads";import{channel}from"node:diagnostics_channel";import{setImmediate}from"node:timers/promises";
//!src/infra/bun-sqlite-close-probe.ts
const closeProbe=channel(`openclaw.sqlite.close-probe`);async function cleanupProbe(e,t,n){try{if(e){if(n)e.unref();await raceWithTimeout(e.terminate(),5e3,()=>{throw new Error(`SQLite close check termination timed out after 5000ms`)},{ref:!n});await setImmediate(void 0,{ref:!n})}if(t)await rm(t,{recursive:true,force:true})}catch(n){e?.unref();const r=`SQLite close check cleanup failed: ${String(n)}; retained ${t}`;process.emitWarning(r,{code:`SQLITE_CLOSE_PROBE_CLEANUP`});return r}}async function probeSqliteNativeClose(){let e;let t;let n;let r;try{e=await mkdtemp(join(tmpdir(),`openclaw-sqlite-close-`));e=await realpath(e);closeProbe.publish({phase:`start`});t=new Worker(resolveRuntimeWorkerUrl(runtimeProcessEntrypoints.sqliteCloseProbe),{workerData:e,execArgv:[]});const i=t;r=await new Promise((e,t)=>{i.once(`message`,n=>{if(typeof n!==`string`){t(/* @__PURE__ */ new Error(`Invalid SQLite close check reply`));return}e({explicitSqliteCloseReleasesNativeResources:n===``,reason:n||`Native close check passed`})});i.once(`error`,t);i.once(`exit`,e=>t(/* @__PURE__ */ new Error(`SQLite close check exited before its reply (${e})`)));n=setTimeout(()=>t(/* @__PURE__ */ new Error(`SQLite close check timed out after 10000ms`)),1e4)})}catch(e){r={explicitSqliteCloseReleasesNativeResources:false,reason:String(e)}}finally{clearTimeout(n)}const i=!r.explicitSqliteCloseReleasesNativeResources;const a=cleanupProbe(t,e,i);if(i)return r;const o=await a;if(o)return{explicitSqliteCloseReleasesNativeResources:false,reason:o};return r}export{probeSqliteNativeClose};