Pops::Loaders thread safety: synchronization in find_loader and [] #9299
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.
Re: #9252
This patch makes reads and writes to Puppet::Pops::Loaders' instance variable @module_resolver thread-safe.
Without this, enabling threading on our stock Puppet 7 masters yields errors of the following form, on ~3-5% of agent runs:
(I theorize that this a race condition between multiple modules in our ecosystem resolving dependencies-in-common at the same time)
Applying this patch does seem to correct the behavior. We've been running this for a while on two of our active masters with no ill effects.
It seems likely that there are other thread-shared instance variables that should be wrapped in
environment.lock.synchronize
. I'm not particularly familiar with this code, so I stuck with the method that was trigger errors for us, as well as a nearby sibling, where it was clear that there was no danger of introducing deadlocks.