Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono] Crash in github runner due to null AssemblyLoadContext.GetLoadContext result #60348

Closed
uweigand opened this issue Oct 13, 2021 · 6 comments · Fixed by #60350
Closed

[mono] Crash in github runner due to null AssemblyLoadContext.GetLoadContext result #60348

uweigand opened this issue Oct 13, 2021 · 6 comments · Fixed by #60350

Comments

@uweigand
Copy link
Contributor

uweigand commented Oct 13, 2021

Description

Attempting to run the GitHub action runner on linux-s390x (using the Mono runtime) crashes on startup.

Reproduction Steps

Building the code base from here: https://github.com/actions/runner and starting the Runner.Worker binary.

Expected behavior

Program starts up without crashing.

Actual behavior

Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
   at GitHub.Runner.Common.HostContext..ctor(String hostType, String logFile) in /home/uweigand/runner/src/Runner.Common/HostContext.cs:line 82
   at GitHub.Runner.Worker.Program.Main(String[] args) in /home/uweigand/runner/src/Runner.Worker/Program.cs:line 14

This happens at https://github.com/actions/runner/blob/main/src/Runner.Common/HostContext.cs#L81

            _loadContext = AssemblyLoadContext.GetLoadContext(typeof(HostContext).GetTypeInfo().Assembly);
            _loadContext.Unloading += LoadContext_Unloading;

because the GetLoadContext call returns null.

Regression?

Likely yes - this looks like another instance of the problem introduced by #53308. A similar case was already fixed here: #55921.

Known Workarounds

Add the following line before the GetLoadContext call to ensure the default ALC was initialized:

            var _ = AssemblyLoadContext.Default;

Configuration

.NET RC1 rebuilt for linux-s390x (Mono runtime based).

Other information

CC @vargaz, @lambdageek

@dotnet-issue-labeler dotnet-issue-labeler bot added area-AssemblyLoader-mono untriaged New issue has not been triaged by the area owner labels Oct 13, 2021
@ghost
Copy link

ghost commented Oct 13, 2021

Tagging subscribers to this area:
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

Attempting to run the GitHub action runner on linux-s390x (using the Mono runtime) crashes on startup.

Reproduction Steps

Building the code base from here: https://github.com/actions/runner and starting the Runner.Worker binary.

Expected behavior

Program starts up without crashing.

Actual behavior

Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
   at GitHub.Runner.Common.HostContext..ctor(String hostType, String logFile) in /home/uweigand/runner/src/Runner.Common/HostContext.cs:line 82
   at GitHub.Runner.Worker.Program.Main(String[] args) in /home/uweigand/runner/src/Runner.Worker/Program.cs:line 14

This happens at https://github.com/actions/runner/blob/main/src/Runner.Common/HostContext.cs#L81

            _loadContext = AssemblyLoadContext.GetLoadContext(typeof(HostContext).GetTypeInfo().Assembly);
            _loadContext.Unloading += LoadContext_Unloading;

because the GetLoadContext call returns null.

Regression?

Likely yes - this looks like another instance of the problem introduced by #53308. A similar case was already fixed here: #55921.

Known Workarounds

Add the following line before the GetLoadContext call to ensure the default ALC was initialized:

            var _ = AssemblyLoadContext.Default;

Configuration

.NET RC1 rebuilt for linux-s390x (Mono runtime based).

Other information

CC @CoffeeFlux, @vargaz, @lambdageek

Author: uweigand
Assignees: -
Labels:

untriaged, area-AssemblyLoader-mono

Milestone: -

@lambdageek
Copy link
Member

@uweigand What if we add

var _ = AssemblyLoadContext.Default;

before

lambdageek added a commit to lambdageek/runtime that referenced this issue Oct 13, 2021
If we try to get the ALC of an assembly from the default context before the
managed default ALC object has been created, the native gchandle has a null
target.
Ensure it is not null by explicitly referencing the Default ALC.

Fixes dotnet#60348
@lambdageek lambdageek removed the untriaged New issue has not been triaged by the area owner label Oct 13, 2021
@lambdageek lambdageek added this to the 6.0.0 milestone Oct 13, 2021
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Oct 13, 2021
@uweigand
Copy link
Contributor Author

That looks like it should work, I'll rebuild my runtime and try it.

@uweigand
Copy link
Contributor Author

Yes, this fixes the problem for me, thanks!

github-actions bot pushed a commit that referenced this issue Oct 14, 2021
If we try to get the ALC of an assembly from the default context before the
managed default ALC object has been created, the native gchandle has a null
target.
Ensure it is not null by explicitly referencing the Default ALC.

Fixes #60348
lambdageek added a commit that referenced this issue Oct 14, 2021
If we try to get the ALC of an assembly from the default context before the
managed default ALC object has been created, the native gchandle has a null
target.
Ensure it is not null by explicitly referencing the Default ALC.

Fixes #60348
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Oct 14, 2021
@lambdageek
Copy link
Member

Reopening until the backport is merged

@lambdageek lambdageek reopened this Oct 14, 2021
mmitche pushed a commit that referenced this issue Oct 15, 2021
If we try to get the ALC of an assembly from the default context before the
managed default ALC object has been created, the native gchandle has a null
target.
Ensure it is not null by explicitly referencing the Default ALC.

Fixes #60348

Co-authored-by: Aleksey Kliger <[email protected]>
@uweigand
Copy link
Contributor Author

This is now fixed everywhere.

@ghost ghost locked as resolved and limited conversation to collaborators Nov 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants