Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sdk/typescript/src/multiscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ async function acquireLock(output: string): Promise<() => Promise<void>> {
await rm(stale, { recursive: true, force: true });
}
}
const createdLock = await lstat(path);
const createdLock = await lstat(path, { bigint: true });
const owner = `${JSON.stringify({
pid: process.pid,
ownerId: randomUUID(),
Expand All @@ -429,7 +429,7 @@ async function acquireLock(output: string): Promise<() => Promise<void>> {
try {
await writeFile(ownerPath, owner, { flag: "wx", mode: 0o600 });
} catch (error) {
const currentLock = await lstat(path).catch(
const currentLock = await lstat(path, { bigint: true }).catch(
(cleanup: NodeJS.ErrnoException) => {
if (cleanup.code !== "ENOENT") throw cleanup;
return undefined;
Expand Down
28 changes: 27 additions & 1 deletion sdk/typescript/tests-ts/multiscan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1388,8 +1388,16 @@ describe("multiscan", () => {
});

test.each([false, true])(
"never removes a replacement lock when owner creation fails (owner published: %s)",
"never removes a replacement lock when owner creation fails (owner published: %p)",
async (ownerPublished) => {
if (
runTestInSubprocess(
import.meta.path,
`never removes a replacement lock when owner creation fails (owner published: ${ownerPublished})`,
)
) {
return;
}
const paths = await fixture();
const source = await repository(paths.root, "owner-creation-race");
await writeFile(
Expand All @@ -1404,7 +1412,23 @@ describe("multiscan", () => {
hostname: hostname(),
processStartedAt: performance.timeOrigin,
});
const createdInode = 2n ** 60n;
const replacementInode = createdInode + 1n;
expect(Number(createdInode)).toBe(Number(replacementInode));
let replaced = false;
const originalLstat = filesystem.lstat;
const originalWriteFile = filesystem.writeFile;
const readLock = spyOn(filesystem, "lstat").mockImplementation((async (
...args: Parameters<typeof filesystem.lstat>
) => {
const metadata = await originalLstat(...args);
if (String(args[0]) === lock) {
const inode = replaced ? replacementInode : createdInode;
metadata.ino =
typeof metadata.ino === "bigint" ? inode : Number(inode);
}
return metadata;
}) as typeof filesystem.lstat);
const writeOwner = spyOn(filesystem, "writeFile").mockImplementation(
async (path, data, options) => {
if (String(path) !== ownerPath) {
Expand All @@ -1413,6 +1437,7 @@ describe("multiscan", () => {
writeOwner.mockRestore();
await rename(lock, join(paths.output, ".lock.stale-owner-creation"));
await mkdir(lock, { mode: 0o700 });
replaced = true;
if (ownerPublished) {
await originalWriteFile(ownerPath, replacement, { mode: 0o600 });
}
Expand All @@ -1439,6 +1464,7 @@ describe("multiscan", () => {
}
} finally {
writeOwner.mockRestore();
readLock.mockRestore();
}
},
);
Expand Down
Loading