Avoid sharing violations on event.json when using background steps on Windows - #24
Merged
Merged
Conversation
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.
Description
This PR introduces a workaround to prevent file-locking errors (sharing violations) on Windows runners when using the new GitHub Actions
backgroundstep feature.To avoid code duplication caused by this workaround, YAML anchors and aliases are utilized.
Proposed Workaround
To safely bypass the file-locking issue on Windows, the following strategy is implemented:
ifconditions: The target step is split into two separate definitions - one for Windows (synchronous execution,backgroundomitted) and one for non-Windows platforms (background: true).&/*): To avoid duplicating step properties (name,uses,with,env), the configuration is declared once in the Windows step and referenced in the non-Windows step.Example Structure:
Appendix 1: Why This Workaround is Necessary (The Windows File-Locking Issue)
When using
background: trueasynchronously on Windows runners, workflows intermittently fail with the following error:Windows enforces strict file-locking mechanisms. When a step runs in the background, a race condition occurs with the runner or subsequent steps accessing
event.json. Because this file is managed by the GitHub Actions infrastructure, direct user intervention or control over this behavior is not possible. This workaround ensures pipeline stability until a platform-side fix becomes available.Appendix 2: Why Alternative Approaches Failed (Technical Limitations)
Ideally, the property would be dynamically toggled using GitHub Actions expressions:
However, verification confirms that the
backgroundproperty does not support runtime expressions. Attempting to use them results in the following parser errors, proving that these contexts are completely unresolvable within this scope:Unrecognized named-value: 'runner'Unrecognized named-value: 'matrix'Unrecognized named-value: 'inputs'Therefore, splitting the steps using YAML anchors remains the only viable solution that maintains code readability.