Skip to content

Append version to RID only with valid characters - #80901

Merged
elinor-fung merged 2 commits into
dotnet:mainfrom
am11:feature/native/corehost
Jan 20, 2023
Merged

elinor-fung merged 2 commits into
dotnet:mainfrom
am11:feature/native/corehost

Conversation

@am11

@am11 am11 commented Jan 20, 2023 •

Copy link
Copy Markdown
Member

On some distros with rolling release model, VERSION_ID is set to a sentinel indicating their versioning model. Arch Linux is one of those distros with VERSION_ID=TEMPLATE_VERSION_ID line in /etc/os-release.

This makes assembly launched with dotnet, dotnet exec or dotnet run unable to function properly, when corehost is built with non-portable flag set: https://github.com/archlinux/svntogit-community/blob/ca544978888af3d305f8ef5051622ff1d04b102c/dotnet-core/trunk/PKGBUILD#L128 (dotnet/source-build recommended) and assembly has a dependency on package with native runtime assets.

Fix is to validate that string contains valid characters (not necessarily conforming to any particular versioning standard), before inserting version into the RID string.

@ghost ghost added community-contribution Indicates that the PR has been added by a community member area-Host labels Jan 20, 2023
@ghost

ghost commented Jan 20, 2023

Copy link
Copy Markdown

Tagging subscribers to this area: @vitek-karas, @agocke, @VSadov
See info in area-owners.md if you want to be subscribed.

Issue Details

On some distros with rolling release model has VERSION_ID set to sentinel to indicate their versioning model. Arch Linux is one of those distros with VERSION_ID=TEMPLATE_VERSION_ID line in /etc/os-release.

This makes assembly launched with dotnet, dotnet exe or dotnet run unable to function properly, when corehost is built with non-portable flag set: https://github.com/archlinux/svntogit-community/blob/ca544978888af3d305f8ef5051622ff1d04b102c/dotnet-core/trunk/PKGBUILD#L128 (dotnet/source-build recommended) and assembly has a dependency on package with native runtime assets.

Fix is to validate that string containing valid characters (not necessarily confirming to any particular versioning standard), before inserting version into the RID string.

Author: am11
Assignees: -
Labels:

area-Host, community-contribution

Milestone: -

@vitek-karas

Copy link
Copy Markdown
Member

@elinor-fung / @janvorli could you please take a look at this (you're much more of Linux experts than I am).

@am11

am11 commented Jan 20, 2023

Copy link
Copy Markdown
Member Author

@elinor-fung, @ViktorHofer, I tested it with a workaround on Arch Linux by renaming VERSION_ID= to XVERSION_ID= and dotnet run was able to load System.IO.Ports's native binary properly. It was .NET 7, downloaded from Arch user repos (pacman -Suy dotnet-sdk). So with this fix, corehost will internally compute arch-x64 with non-portable build instead of arch.TEMPLATE_VERSION_ID-x64.

--- before
+++ after

$ COREHOST_TRACE=1 COREHOST_TRACE_VERBOSITY=4 dotnet run 2>&1 | grep 'HostRID is'
- HostRID is arch.TEMPLATE_VERSION_ID-x64
+ HostRID is arch-x64

- exit code: 134
+ exit code: 0

@ViktorHofer

Copy link
Copy Markdown
Member

cc @Foxlider

This is a huge improvement and explains why the wrong runtime assets are chosen on ARCH Linux. Fantastic find, @am11 👍👍

@janvorli janvorli left a comment

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.

LGTM, thank you!

@elinor-fung elinor-fung left a comment

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.

Thank you! I imagine this will fix some really confusing failures.

@elinor-fung

Copy link
Copy Markdown
Member

@am11 Do you know what other distros this affects? And if there are specific open issues on this already?

This seems like something worth backporting.

@elinor-fung
elinor-fung merged commit 31e4f40 into dotnet:main Jan 20, 2023
@am11

am11 commented Jan 20, 2023

Copy link
Copy Markdown
Member Author

@elinor-fung, there is one scenario in #79196 which I was investigating. My attempt to manually test with source-build failed, so once VMR is ready after preview 1, I will retry. Meanwhile I did some improvised testing #80901 (comment) to make sure it solved at least the corehost side of the problem (even if it is a partial fix, we have a workaround for user: edit /etc/os-release and delete VERSION_ID line).


The problem is that RID is calculated in multiple places with different conditions and non-portable RIDs only make things more harder (there are hundreds of (600+) linux distros out there). All these varied implementations have different outcomes in different situations:

  • RID calculated to build runtime (corehost and runtime installer packages; among other things like crossgen2 and soon ILC and more..) is in bash script.
    if [ -z "${VERSION_ID+x}" ]; then
    (this condition with +x itself is "wrong", it should be without +x to support empty VERSION_ID value, so the final string looks like arch-x64 instead of arch.-x64)
  • RID calculated by SDK to build apps. It is passed to NuGet and MSBuild is in msbuild script (seeded from installer repo, get mutated in SDK)
  • RID calculated for dotnet --info in C# code, which does not differentiate between portable and non-portable build (both will give us arch-x64, ubuntu.22.04-arm64 etc.), so as it stands, it is just good for loose telemetry and nothing concrete and accurate.
  • and this RID calculation in corehost at run-time written in C++.

@am11
am11 deleted the feature/native/corehost branch January 21, 2023 02:20
mdh1418 pushed a commit to mdh1418/runtime that referenced this pull request Jan 24, 2023
* Append version to RID only with valid characters

* Handle empty version case
@ghost ghost locked as resolved and limited conversation to collaborators Feb 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-Host community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants