esy-issues
esy-issues copied to clipboard
Implementing locking to prevent concurrent builds from racing with each other
We need to implement locking so that concurrent builds for the same package won't race.
See flock or... suggestions?
That could help: https://github.com/discoteq/flock
The question is how do we introduce flock
to an esy's environment? It is not desirable we require it installed as external dep.
One option is to make flock
an npm package too and model it as a dependency of every build (esy doesn't have such an ability yet, we should design it and implement). Then we modify esyBuildRuntime.sh
to use flock
command if it's available (it is not available during the build of flock
itself.).
Catching up with esy.
What's the purpose of this lock specifically? To protect concurrent builds for same package for one project (OCaml is a dependency of many targets inside of one project, so we need to protect it), or to protect concurrent builds for the same package under different projects (for example, building ReasonReactProject and ReasonProject at the same time)?
If it is the for the first case, another thing we can try is to create a lock file with O_EXCL and O_CREAT (works across all unix systems). The caveat of that is to release a lock, the process needs to explicitly delete that file, which wouldn't happen in the process is terminated by external signals. However, if we defensively remove the file at the beginning of each project build as a clean up process for previous build, a failed build won't affect the next build.
to protect concurrent builds for the same package under different projects (for example, building ReasonReactProject and ReasonProject at the same time)?
This one. The first case is covered with how with execute builds through make.
Is this done?