Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ArgumentNullException: Value cannot be null, for anonymous volume mounts#426

Merged
dakale merged 3 commits into
masterfrom
dakale/runtime-466
Apr 14, 2020
Merged

ArgumentNullException: Value cannot be null, for anonymous volume mounts#426
dakale merged 3 commits into
masterfrom
dakale/runtime-466

Conversation

@dakale

@dakale dakale commented Apr 14, 2020

Copy link
Copy Markdown
Contributor

This was introduced due to #384

Given a workflow like:

jobs:
  test:
    runs-on: ubuntu-latest
    container:
      image: ubuntu
      volumes:
        - /data
  steps:
  - run: echo hi

we now properly mount the anonymous volume per https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idcontainervolumes

But anonymous volumes do not have a source path, so the SourceVolume is null and we cant resolve those paths from host to container. We get the following exception:

##[error]Value cannot be null. (Parameter 'value')
##[debug]System.ArgumentNullException: Value cannot be null. (Parameter 'value')
##[debug]   at System.String.StartsWith(String value)
##[debug]   at GitHub.Runner.Worker.Handlers.ContainerStepHost.<>c__DisplayClass14_0.<ResolvePathForStepHost>b__0(MountVolume x) in /home/dakale/dev/runner/src/Runner.Worker/Handlers/StepHost.cs:line 115
##[debug]   at System.Collections.Generic.List`1.FindIndex(Int32 startIndex, Int32 count, Predicate`1 match)
##[debug]   at System.Collections.Generic.List`1.Exists(Predicate`1 match)
##[debug]   at GitHub.Runner.Worker.Handlers.ContainerStepHost.ResolvePathForStepHost(String path) in /home/dakale/dev/runner/src/Runner.Worker/Handlers/StepHost.cs:line 115
##[debug]   at GitHub.Runner.Worker.Handlers.ScriptHandler.RunAsync(ActionRunStage stage) in /home/dakale/dev/runner/src/Runner.Worker/Handlers/ScriptHandler.cs:line 225
##[debug]   at GitHub.Runner.Worker.ActionRunner.RunAsync() in /home/dakale/dev/runner/src/Runner.Worker/ActionRunner.cs:line 205
##[debug]   at GitHub.Runner.Worker.StepsRunner.RunStepAsync(IStep step, CancellationToken 

If the volume mount is coming from an anonymous volume the target script to run in the container can not possibly exist in that volume on the host, since these volumes are created on the fly, so theres no need to try to resolve the container path for that mount

I believe this was not an issue in the past due to changing when we expand and add the full MountVolumes objects to the ContainerInfo

@dakale dakale requested a review from TingluoHuang April 14, 2020 17:33
Comment thread src/Runner.Worker/Handlers/StepHost.cs Outdated
// try to resolve path inside container if the request path is part of the mount volume
#if OS_WINDOWS
if (Container.MountVolumes.Exists(x => path.StartsWith(x.SourceVolumePath, StringComparison.OrdinalIgnoreCase)))
if (Container.MountVolumes.Exists(x => x.SourceVolumePath != null && path.StartsWith(x.SourceVolumePath, StringComparison.OrdinalIgnoreCase)))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will string.isnullorempty better?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably yes. All strings would technically start with "" so if it were empty we would unnecessarily call Container.TranslateToContainerPath. SourcePath shouldnt be empty but its probably safer

@dakale dakale merged commit c126b52 into master Apr 14, 2020
@dakale dakale deleted the dakale/runtime-466 branch April 14, 2020 18:36
TingluoHuang pushed a commit that referenced this pull request Apr 15, 2020
…nts (#426)

* Dont check if path starts with null

* Check SourceVolumePath not MountVolume obj

* Prefer string.IsNullOrEmpty

@Cunero Cunero left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate of #@^*

AdamOlech pushed a commit to antmicro/runner that referenced this pull request Jan 28, 2021
…nts (actions#426)

* Dont check if path starts with null

* Check SourceVolumePath not MountVolume obj

* Prefer string.IsNullOrEmpty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants