Skip to content

Conversation

@rdziarnowski-clickup
Copy link

Changed createEmptyTmpFile to use the 'wx' flag when writing the lock file, which fails if the file already exists. Added error handling to catch and ignore EEXIST errors, allowing the lock mechanism to work correctly when the lock file already exists from a previous operation.

This prevents race conditions and improves robustness of the file locking mechanism by properly handling the case where multiple processes or sequential calls attempt to create the same lock file.

Changed createEmptyTmpFile to use the 'wx' flag when writing the lock file,
which fails if the file already exists. Added error handling to catch and
ignore EEXIST errors, allowing the lock mechanism to work correctly when
the lock file already exists from a previous operation.

This prevents race conditions and improves robustness of the file locking
mechanism by properly handling the case where multiple processes or sequential
calls attempt to create the same lock file.

Added comprehensive tests covering:
- Basic lock functionality with sync and async functions
- Lock file creation and cleanup
- Error handling and lock release
- Concurrent lock acquisition
- Handling of existing lock files
- Return value propagation
@netlify
Copy link

netlify bot commented Oct 20, 2025

Deploy Preview for testcontainers-node ready!

Name Link
🔨 Latest commit 91aafe0
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-node/deploys/68f68e95be892c0008dea3b6
😎 Deploy Preview https://deploy-preview-1164--testcontainers-node.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@rdziarnowski-clickup rdziarnowski-clickup changed the title Fix file-lock to handle existing lock files with EEXIST error Fix file-lock to handle existing lock files Oct 20, 2025
@cristianrgreco
Copy link
Collaborator

Hi @rdziarnowski-clickup, I don't understand what specific scenario this PR fixes. How the temporary file is created shouldn't matter. If it already exists it means we should wait for the lock to be released, not to throw an error. If I revert all the changes made to file-lock.ts and run the new test suite everything passes.

import path from "path";
import { withFileLock } from "./file-lock";

describe("withFileLock", () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running this test suite fails intermittently on my machine. It's because the tests by default run in parallel, and these tests which share a file lock inherently cannot run in parallel. Needs to be describe.sequential.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants