@osfactory/otel-hook 0.13.0 → 0.13.1

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/state.js CHANGED
@@ -1016,7 +1016,7 @@ var createBoundedMemoryStateStore = (options) => {
1016
1016
 
1017
1017
  // src/state/filesystem-store.ts
1018
1018
  import { randomBytes } from "crypto";
1019
- import { mkdir, open, readFile, readdir, rename, unlink, writeFile } from "fs/promises";
1019
+ import { mkdir, open, readFile, readdir, rename, stat, unlink, writeFile } from "fs/promises";
1020
1020
  import * as path from "path";
1021
1021
 
1022
1022
  // src/state/keys.ts
@@ -1038,8 +1038,7 @@ var keyDigest = (key) => createHash("sha256").update(key, "utf8").digest("hex");
1038
1038
  // src/state/filesystem-store.ts
1039
1039
  var isErrnoException = (thrown, code) => thrown instanceof Error && thrown.code === code;
1040
1040
  var sleep = (millis) => new Promise((resolve) => {
1041
- const timer = setTimeout(resolve, millis);
1042
- timer.unref?.();
1041
+ setTimeout(resolve, millis);
1043
1042
  });
1044
1043
  var wrapFsError = (thrown, operation) => {
1045
1044
  if (thrown instanceof Error) {
@@ -1159,14 +1158,29 @@ var createFilesystemStateStore = (options) => {
1159
1158
  }
1160
1159
  }
1161
1160
  const stale = await (async () => {
1161
+ let raw;
1162
+ try {
1163
+ raw = await readFile(filePath, "utf8");
1164
+ } catch (thrown) {
1165
+ return isErrnoException(thrown, "ENOENT") ? "gone" : true;
1166
+ }
1162
1167
  try {
1163
- const raw = await readFile(filePath, "utf8");
1164
1168
  const parsed = JSON.parse(raw);
1165
- return typeof parsed.acquiredAt !== "number" || options.clock.now() - parsed.acquiredAt > lockStaleMillis;
1169
+ if (typeof parsed.acquiredAt === "number") {
1170
+ return options.clock.now() - parsed.acquiredAt > lockStaleMillis;
1171
+ }
1166
1172
  } catch {
1167
- return true;
1173
+ }
1174
+ try {
1175
+ const stats = await stat(filePath);
1176
+ return Date.now() - stats.mtimeMs > lockStaleMillis;
1177
+ } catch {
1178
+ return "gone";
1168
1179
  }
1169
1180
  })();
1181
+ if (stale === "gone") {
1182
+ continue;
1183
+ }
1170
1184
  if (stale) {
1171
1185
  await unlink(filePath).catch(() => void 0);
1172
1186
  continue;