elm / compiler

Compiler for Elm, a functional language for reliable webapps.
https://elm-lang.org/
BSD 3-Clause "New" or "Revised" License
7.51k stars 656 forks source link

Parallel elm make calls corrupt elm-stuff/0.19.1/i.dat #2187

Open omnibs opened 3 years ago

omnibs commented 3 years ago

Quick Summary: Elm make running in parallel corrupts elm-stuff/0.19.1/i.dat

Running elm-make in parallel to compile different entry points every now and then errors out with the message below:

Compiling ...+-------------------------------------------------------------------------------
|  Corrupt File: /build/source/myproject/elm-stuff/0.19.1/i.dat
|   Byte Offset: 102336
|       Message: not enough bytes
|
| Please report this to https://github.com/elm/compiler/issues
| Trying to continue anyway.
+-------------------------------------------------------------------------------

-- CORRUPT CACHE ---------------------------------------------------------------

It looks like some of the information cached in elm-stuff/ has been corrupted.

Try deleting your elm-stuff/ directory to get unstuck.

Note: This almost certainly means that a 3rd party tool (or editor plugin) is
causing problems your the elm-stuff/ directory. Try disabling 3rd party tools
one by one until you figure out which it is!

Additional Details

This has been mentioned in https://github.com/elm/compiler/issues/1830#issuecomment-727259777, we found it by searching for the error message.

We were facing the same problem when using esbuild's elm plugin. I opened an issue on the plugin's side here: https://github.com/phenax/esbuild-plugin-elm/issues/2

There might be other spots https://github.com/elm/compiler/commit/054fa04074fd819958affd04a526e10f69aa5197 didn't cover that might be worth locking on.

Work-around

Don't let elm run in parallel.

It might be hard to track who's launching elm in parallel. It was for us. To track down all places we wrapped the elm executable in a shell script that blew every elm up when launching more than one instance of elm in parallel. This way we also caught a failures in the already-running elm callsite once a parallel launch was attempted.

github-actions[bot] commented 3 years ago

Thanks for reporting this! To set expectations:

Finally, please be patient with the core team. They are trying their best with limited resources.

omnibs commented 3 years ago

Not sure if it's relevant, but we were also observing o.dat get corrupted.

jjant commented 2 years ago

@evancz Any plans to make the compiler able to run in parallel?

phenax commented 2 years ago

Any updates on this?

lydell commented 2 years ago

I have one potential update. In my experience, Elm has a file based lock so that parallel elm make actually run in sequence. However, there is no lock for the “dependencies” part of the compilation – that’s where I’ve seen failures. So what I did in my case was to first run elm make --output /dev/null Dummy.elm to force the dependencies stuff to be done, then I started my parallel elm make processes.

omnibs commented 2 years ago

We tried serial dependency fetching -> parallel compilation, and can report it didn't work for us. We still ran into the same issue described in the OP and had to quickly revert.

I'm not contesting @lydell's report tho. The trick might indeed reduce the likelihood of corruption, but that reduction wasn't enough to prevent corruption from happening frequently in a codebase with so many Elm apps to be compiled in parallel as NoRedInk's codebase.