inibase 1.5.10 → 1.5.11
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/dist/file.js +7 -1
- package/package.json +1 -1
package/dist/file.js
CHANGED
|
@@ -8,6 +8,8 @@ import Inison from "inison";
|
|
|
8
8
|
import { globalConfig, } from "./index.js";
|
|
9
9
|
import { detectFieldType, isArrayOfObjects, isNumber, isObject, isStringified, } from "./utils.js";
|
|
10
10
|
import { compare, encodeID, exec, gunzip, gzip } from "./utils.server.js";
|
|
11
|
+
// Locks older than this are assumed abandoned by a crashed/killed process, not a slow operation.
|
|
12
|
+
const STALE_LOCK_MS = 30_000;
|
|
11
13
|
export const lock = async (folderPath, prefix) => {
|
|
12
14
|
let lockFile = null;
|
|
13
15
|
const lockFilePath = join(folderPath, `${prefix ?? ""}.locked`);
|
|
@@ -16,8 +18,12 @@ export const lock = async (folderPath, prefix) => {
|
|
|
16
18
|
return;
|
|
17
19
|
}
|
|
18
20
|
catch ({ message }) {
|
|
19
|
-
if (message.split(":")[0] === "EEXIST")
|
|
21
|
+
if (message.split(":")[0] === "EEXIST") {
|
|
22
|
+
const lockStat = await stat(lockFilePath).catch(() => null);
|
|
23
|
+
if (lockStat && Date.now() - lockStat.mtimeMs > STALE_LOCK_MS)
|
|
24
|
+
await unlink(lockFilePath).catch(() => { });
|
|
20
25
|
return await new Promise((resolve) => setTimeout(() => resolve(lock(folderPath, prefix)), 13));
|
|
26
|
+
}
|
|
21
27
|
}
|
|
22
28
|
finally {
|
|
23
29
|
await lockFile?.close();
|