Require terraform-docs runs in serial #33
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It turns out that
pre-commit
defaults to running hooks in parallel. This means it will take a batch of files, break them into chunks, and run those together. Theterraform_docs.sh
script 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: true
to 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-docs
pre-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
sed
and had less failures but it would happen, just less often. I think the combination ofperl
anddocker
is what made this show up becauseperl
takes just a bit longer thansed
anddocker
is 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: