runtime: Segmentation fault when .NET starts JIT compilation of previous recorded methods triggered by `ProfileOptimization.StartProfile`

Description

We PowerShell team got 2 reports about Segmentation fault when starting PowerShell by pwsh -command or pwsh -file on Redhat 7.9 and macOS M1 machine.

The stack trace for the report on macOS M1 machine is attached below. The stack trace suggests the crash happened when .NET starts JIT compilation of the previous recorded methods, which is triggered by the ProfileOptimization.StartProfile call in PowerShell.

We asked the user to delete the profile data file and try launch pwsh -c or pwsh -file again, and the user reported back that it began to work after removing the profile data file: https://github.com/PowerShell/PowerShell/issues/18958#issuecomment-1416367110. So, it’s confirmed that this is an issue with the .NET profile optimization.

image

Reproduction Steps

The issue doesn’t happen consistently. Even for the users who reported the issue, it was not consistent. They started with using PowerShell 7.3.1, which worked for a few days and then started to fail. Then they switched to PowerShell 7.3.0, which worked for a few days and started to fail again.

PowerShell 7.3.1 and PowerShell 7.3.0 are both on top of .NET 7.0.0

Expected behavior

No segmentation fault.

Actual behavior

Segmentation fault was reported.

Regression?

It’s a regression, given that we don’t have the problem in PowerShell 7.2.x versions, which are on top of .NET 6.

Known Workarounds

Deleting the profile data file, then pwsh -c and pwsh -file will start to work again.

Configuration

Which version of .NET is the code running on? .NET 7.0.0

What OS and version, and what distro if applicable? Redhat 7.9 and macOS M1 machine

What is the architecture (x64, x86, ARM, ARM64)? For Redhat 7.9: Linux 3.10.0-1160.81.1.el7.x86_64 For macOS: ARM64

Other information

No response

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Comments: 19 (10 by maintainers)

Most upvoted comments

Just emailed that profile data file. It does not seem to matter what is run, I’m running .ps1 files directly from bash that have a #!/usr/bin/pwsh in the first line. But even running a simple command fails: pwsh -command Write-Output "ok" Segmentation fault (core dumped)

I believe I’m seeing this with Paint.NET. Or rather, I’m getting several reports of it. I’ve never had it manifest on its own on my system.

Steps to repro:

  1. Download and install Paint.NET v5.0.11, or use the portable version. Both available here: https://github.com/paintdotnet/release/releases/tag/v5.0.11 . That version of Paint.NET is using .NET 7.0.12

  2. Place the two files in this ZIP into %LOCALAPPDATA%\paint.net\Optimization: Startup.profiles.bad.zip image

  3. Try to start Paint.NET, either by double-clicking its icon or running paintdotnet.exe at the command-line

Expected: It works

Actual: App does not start, and you see errors in the event viewer like so: image

If this isn’t the same issue then I can file a new issue for it, but this is causing misery for a non-trivial number of people who use my app 😢 In the short-term I can just disable the use of ProfileOptimization and release a hotfix for the app

Thanks for the data @nitroed01, I’m able to reproduce the issue. Not clear yet where the problems are, I’ll investigate.

Ran into this issue on AlmaLinux release 8.6, running Powershell 7.2.6. I upgraded to 7.3.6 and the issue went away for about a month, now the problem is back. This is also on a server running Nagios so pwsh is being called 100+ times per minute. I do have a copy of the corrupt StartupProfileData-NonInteractive file as I simply renamed it go get things working, if that would be of help.