fix: avoid race condition when evaluating runs-on with matrix strategy#6050
Open
xingzihai wants to merge 1 commit intonektos:masterfrom
Open
fix: avoid race condition when evaluating runs-on with matrix strategy#6050xingzihai wants to merge 1 commit intonektos:masterfrom
xingzihai wants to merge 1 commit intonektos:masterfrom
Conversation
Issue nektos#5971: Matrix multi-runner inconsistency When using matrix strategy with multiple platforms (windows-latest, macos-latest, ubuntu-latest), results were inconsistent. Sometimes all 3 runners were reported as unsupported, even when ubuntu-latest was properly configured. Root cause: EvaluateYamlNode modifies the yaml.Node in-place via ret.Decode(node). Multiple matrix jobs running in parallel share the same Job object, so concurrent calls to runsOnPlatformNames() raced to modify job.RawRunsOn, causing inconsistent evaluation results. Solution: - Added EvaluateYamlNodeGetResult method to ExpressionEvaluator interface that returns the evaluated node without modifying the original - Modified runsOnPlatformNames to use the new method - Added helper functions extractRunsOnFromNode and nodeAsStringSlice to extract platform names from the returned evaluated node This fix ensures each matrix job evaluates its own runs-on expression without interfering with other parallel matrix jobs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes a race condition that caused inconsistent results when using matrix strategy with multiple platforms (windows-latest, macos-latest, ubuntu-latest).
Problem
When running matrix jobs in parallel:
NewParallelExecutorJobobject (same workflow definition)runsOnPlatformNames()callsEvaluateYamlNode(ctx, &job.RawRunsOn)which modifies the yaml.Node in-placejob.RawRunsOncaused race conditionsRoot Cause
The
EvaluateYamlNodemethod modifies the yaml.Node in-place viaret.Decode(node). When multiple goroutines evaluated matrix jobs concurrently, they would race to modify the sharedjob.RawRunsOnnode.Solution
EvaluateYamlNodeGetResult(context.Context, *yaml.Node) (*yaml.Node, error)toExpressionEvaluatorinterfacerunsOnPlatformNamesto use the new methodextractRunsOnFromNodeandnodeAsStringSliceChanges
pkg/runner/expression.go- Added new interface methodpkg/runner/run_context.go- Modified to use new method, added helpersFixes #5971