haskell / haskell/cabal

Race condition in "cabal run"

Open
#11,298 4 comments 0 reactions 0 assignees View on GitHub
cabal-install: cmd/build cabal-install: cmd/run cabal-install: v2-build system type: bug
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

### Context:

I am working on a project that has dozens of packages and ~10 executables. I have created a process-compose.yml that allows me to run the executables in parallel. Each executable is run via `cabal run the-executable` for simplicity.

### Problem:

If the executables need to be rebuilt, or more precisely, a dependency within the project need to be rebuilt, I regularly see errors that look like race conditions caused by a lack of locking. One such error looked like:

```
ghc-pkg-9.6.6: cannot create: /path/to/project/dist-newstyle/build/x86_64-linux/ghc-9.6.6/THE-DEPENDENCY-0.2.0.0/noopt/package.conf.inplace already exists
```

Obviously this particular error is coming from ghc-pkg, so you could argue it's a ghc-pkg bug. But I assume cabal is responsible for the invocations of ghc-pkg in the first place. As the coordinator, cabal should probably recognize when another instance is already building a given package, and wait.

**Cabal version:** 3.12.1.0

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the failure with several parallel `cabal run` commands in a multi-package project, using the reported Cabal version and error path as reference. Trace how Cabal coordinates concurrent builds and ghc-pkg invocations; done means parallel runs no longer collide when rebuilding a shared dependency.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.