Skip to content

Background actions frequently fail on Windows due to locking event.json #4641

Description

@j3parker

Describe the bug

Every action step writes the event.json file before executing, which causes action-based background steps to frequently fail on Windows due to file-locking.

To Reproduce

In this repository I made a simple reusable action at the top of the repo:

runs:
  using: 'composite'
  steps:
    - run: echo hello
      shell: bash

I then added a workflow to execute that a bunch on Linux and Windows:

on: push

jobs:
  job:
    runs-on:  ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, windows-latest]
        counter: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
    steps:
      - parallel:
        - uses: $/
        - uses: $/
        - uses: $/
        - uses: $/
        - uses: $/
        - uses: $/
        - uses: $/
        - uses: $/
        - uses: $/
        - uses: $/
        - uses: $/
        - uses: $/

Expected behavior

The Linux ones always pass, unsurprisingly. This is the expected behaviour.

Runner Version and Platform

2.336.0 on windows-latest (and self-hosted Windows, with the same runner version)

What's not working?

On Windows, steps frequently fail with this error:

Error: The process cannot access the file 'D:\a_temp_github_workflow\event.json' because it is being used by another process.

I think this is likely due to this bit of code in the runner which writes event.json for every action. See ActionRunner.RunAsync() in the stack trace below.

Job Log Output

From https://github.com/j3parker/github-actions-parallel-tests/actions/runs/32063332105

With debugging enabled:

##[debug]Evaluating condition for step: 'Run j3parker/github-actions-parallel-tests@7c5d69fbd5a4044bbb0ec5b455cdd283177dd7d6'
##[debug]Evaluating: success()
##[debug]Evaluating success:
##[debug]=> true
##[debug]Result: true
##[debug]Loading inputs
##[debug]Loading env
Run j3parker/github-actions-parallel-tests@7c5d69fbd5a4044bbb0ec5b455cdd283177dd7d6
##[debug]Set step '' display name to: 'Run echo hello'
Run echo hello
0s
  ##[debug]Evaluating condition for step: 'Run echo hello'
  ##[debug]Evaluating: success()
  ##[debug]Evaluating success:
  ##[debug]=> true
  ##[debug]Result: true
  ##[debug]Starting: Run echo hello
  Error: The process cannot access the file 'D:\a\_temp\_github_workflow\event.json' because it is being used by another process.
  ##[debug]System.IO.IOException: The process cannot access the file 'D:\a\_temp\_github_workflow\event.json' because it is being used by another process.
  ##[debug]   at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
  ##[debug]   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
  ##[debug]   at System.IO.File.OpenHandle(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
  ##[debug]   at System.IO.File.WriteToFile(String path, FileMode mode, String contents, Encoding encoding)
  ##[debug]   at GitHub.Runner.Worker.ExecutionContext.WriteWebhookPayload()
  ##[debug]   at GitHub.Runner.Worker.ActionRunner.RunAsync()
  ##[debug]   at GitHub.Runner.Worker.Handlers.CompositeActionHandler.RunStepAsync(IStep step)
  ##[debug]Finished: Run echo hello

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions