@@ -149,30 +149,38 @@ export const lockHolderScript = `
149149 console.log("LOCK_ACQUIRED");
150150 console.error("Lock acquired at:", new Date().toISOString());
151151
152- // Hold lock for specified time using setTimeout
153- setTimeout(() => {
154- try {
155- // Final update before releasing
156- db.exec("UPDATE lock_test SET value = 999 WHERE id = 1");
157- db.exec("COMMIT");
158- console.log("LOCK_RELEASED");
159- console.error("Lock released at:", new Date().toISOString());
160- } catch (e) {
161- console.error("Error during commit:", e.message);
162- try {
163- db.exec("ROLLBACK");
164- } catch (rollbackError) {
165- console.error("Error during rollback:", rollbackError.message);
166- }
167- } finally {
152+ // Keep process alive until we're done
153+ let keepAlive = true;
154+
155+ // Hold lock for specified time
156+ const startTime = Date.now();
157+ const checkInterval = setInterval(() => {
158+ if (Date.now() - startTime >= lockHoldTime) {
159+ clearInterval(checkInterval);
168160 try {
169- db.close();
170- } catch (closeError) {
171- console.error("Error closing database:", closeError.message);
161+ // Final update before releasing
162+ db.exec("UPDATE lock_test SET value = 999 WHERE id = 1");
163+ db.exec("COMMIT");
164+ console.log("LOCK_RELEASED");
165+ console.error("Lock released at:", new Date().toISOString());
166+ } catch (e) {
167+ console.error("Error during commit:", e.message);
168+ try {
169+ db.exec("ROLLBACK");
170+ } catch (rollbackError) {
171+ console.error("Error during rollback:", rollbackError.message);
172+ }
173+ } finally {
174+ try {
175+ db.close();
176+ } catch (closeError) {
177+ console.error("Error closing database:", closeError.message);
178+ }
179+ keepAlive = false;
180+ process.exit(0);
172181 }
173- process.exit(0);
174182 }
175- }, lockHoldTime);
183+ }, 10); // Check every 10ms
176184
177185 } catch (e) {
178186 console.error("Error acquiring lock:", e.message);
0 commit comments