Fix custom component registry access #6811
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.
PR Description
There is a small window where the loader is reloading (a new config is being applied) while a custom component is concurrently being re-evaluated.
To get its config, the custom component must check the custom component registry during its evaluation. This registry is re-created every time a config is applied. This means that there is a possibility that the custom component being re-evaluated is looking at a registry that is not fully initialized and might not have yet loaded the config needed. This results in a panic.
The provided fix locks the mutex before the re-evaluation to prevent both evaluations from running concurrently. In other words, the re-evaluation is paused when a new config is applied.
I added a test that triggers the bug 80% of the time on my computer. With the fix it always passes.
I also ran all import tests 50 times to check for regressions.
Which issue(s) this PR fixes
Fixes #6795
PR Checklist