esy-issues icon indicating copy to clipboard operation
esy-issues copied to clipboard

Implementing locking to prevent concurrent builds from racing with each other

Open andreypopp opened this issue 8 years ago • 4 comments

We need to implement locking so that concurrent builds for the same package won't race.

See flock or... suggestions?

andreypopp avatar Dec 30 '16 12:12 andreypopp

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.).

andreypopp avatar Jan 02 '17 09:01 andreypopp

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.

yunxing avatar Jan 03 '17 00:01 yunxing

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.

andreypopp avatar Jan 03 '17 09:01 andreypopp

Is this done?

jordwalke avatar Feb 19 '17 09:02 jordwalke