Require terraform-docs runs in serial#33
Conversation
…lel operations on similar file paths
|
@antonbabenko - Can I do anything for you to help move this along? |
|
Thanks for opening this issue! I will merge it right away. Unfortunately (or luckily, lol) I have not seen this bug before because codebase I work with is usually pretty small. Just curious, what size of your code which reveals this problem? |
|
v1.9.0 has been released. PS: We now have CHANGELOG.md also !!! 🎉 |
|
Thanks for responding so quickly! We have 68 |
|
This does not sound like a lot of files. Good that it helps. I wonder if #31 will be fast enough comparing to |
|
I'd be curious to know if it's fast enough. My guess is that you'll still have a race condition that will pop up from time to time. |
It turns out that
pre-commitdefaults to running hooks in parallel. This means it will take a batch of files, break them into chunks, and run those together. Theterraform_docs.shscript strips the filenames and runs over a set of unique paths. That means that parallel operations can be running int he same directories. To avoid pre-commit doing parallel operations on similar file paths I've addedrequire_serial: trueto the hook descriptions.For some detail, I ran into this while running on docker. I copied a large terraform directory into a docker container and then ran the
terraform-docspre-commit hook to mimic our CI environment in CircleCI. In about 10-20% of cases the hook would fail and the result would be that one or more files were deleted. It turns out the chunking from pre-commit is non-deterministic, so sometimes similar directories would be groups and sometimes not. And when they were not grouped we had a race condition where perl would be operating on an in-place file operation when the underlying file would get removed.I attempted to revert to using
sedand had less failures but it would happen, just less often. I think the combination ofperlanddockeris what made this show up becauseperltakes just a bit longer thansedanddockeris resource constrained enough on my mac to cause the race condition to bite me.Fortunately this is a one-line fix and users who are currently experiencing this can immediately fix it by adding the same line, per this example: