Skip to content

Segmentation fault when .NET starts JIT compilation of previous recorded methods triggered by ProfileOptimization.StartProfile #81799

Closed

Description

@daxian-dbw

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: PowerShell/PowerShell#18958 (comment). 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

Activity

  1. ghost added
    untriaged
    on Feb 7, 2023
  2. daxian-dbw commented on Feb 22, 2023

    @daxian-dbw
    ContributorAuthor

    Any updates? We got another report of the issue in PowerShell repo, and this time it's on Ubuntu 22.04

    The error occurs once a day only on a specific machine user, who executes a lot of pwsh scripts. After a reboot powershell is working fine for approx. 24 hours. Then the issue occus again.

  3. bobrozelle commented on Mar 7, 2023

    @bobrozelle

    We wrote an entire file processing framework using PowerShell, now the business team is thinking of rejecting the roll-out of this because of this problem and asking us to use Bash instead. Need this addressed. It is a regression and should receive attention.

  4. AndyAyersMS commented on Mar 9, 2023

    @AndyAyersMS
    Member

    @mangod9 seems like a runtime issue?

  5. mangod9 commented on Mar 9, 2023

    @mangod9
    Member

    @davidwrighton @kouvel. Does Powershell use multicore JIT functionality? @daxian-dbw, is there a dump available to look at?

  6. removed
    untriaged
    on Mar 9, 2023
  7. added this to the 8.0.0 milestone on Mar 9, 2023
  8. daxian-dbw commented on Mar 9, 2023

    @daxian-dbw
    ContributorAuthor

    Does Powershell use multicore JIT functionality?

    Yes, PowerShell calls ProfileOptimization.SetProfileRoot/StartProfile at the entry point.
    We don't have a dump available. If you can provide steps to collect a dump in this particular case, I think @bobrozelle may be able to help with that when the issue happens again in their environment.

  9. kouvel commented on Mar 28, 2023

    @kouvel
    Contributor

    The repro appears to be simple enough, if we have the right profile data file to cause the seg fault. When the seg fault is seen, and is reproducible with a simple pwsh command, could you please collect the profile data file and share it? I figure it may be reproducible elsewhere too with the same profile data file.

  10. AdminValida commented on May 2, 2023

    @AdminValida

    Hi!

    We are using pwsh scripts for monitoring several things with Check_MK/Nagios. It runs under one user account and fires up to 100 pwsh calls per minute and parallel. Basically i think we can into two "different" issues:

    1. In irregular intervals we get the following error message. This can happen 4 times an hour or every 4 hour once, i was not able to constantly reproduce this error:
      kernel: [15300.129929] pwsh[1328960]: segfault at 28 ip 00007fb77a95fc30 sp 00007fb7739fe8e0 error 4 in libcoreclr.so[7fb77a82d000+383000]

    2. Last week the whole "server" crashed and every pwsh call ends up with the following error. I was able to reproduce the error and temporarily fix it by deleting the file "StartupProfileData-NonInteractive":
      Stack overflow.

    My workaround was just to downgrade powershell to version 7.1.x, since we had to upgrade to Ubuntu 22 the lowest available powershell version is 7.2.x and we again ran into this issue. I found another workaround to shut down creating the cache files and thus powershell is not using them:

    sudo chmod 555 $HOME/.cache/powershell/
    sudo rm $HOME/.cache/powershell/*
    

    I am not able to reproduce this error, and we only have one productive system with such a large amount of pwsh calls. So i think i am not able to deliver a "corrupt" profile data file. Let me know if i can help further.

    Regards

  11. mangod9 commented on May 2, 2023

    @mangod9
    Member

    @AdminValida are you able to collect a dump when the segFault occurs? That might help diagnose the issue.

  12. AdminValida commented on May 3, 2023

    @AdminValida

    @mangod9

    As this is a production system our focus is to not have any segfaults :-)

    But i ll try to reproduce the issue on the coming weekend. Maybe i can get both, a core dump and a "corrupted" profile file.

    I'll keep you up to date

    Regards

  13. mangod9 commented on May 3, 2023

    @mangod9
    Member

    yeah sounds good.

  14. 12 remaining items

  15. rickbrew commented on Nov 25, 2023

    @rickbrew
    Contributor

    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
    1. 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

  16. rickbrew commented on Apr 29, 2024

    @rickbrew
    Contributor

    Judging by commits, this appears to be fixed? Should the issue be closed?

  17. mangod9 commented on Apr 29, 2024

    @mangod9
    Member

    yeah this could be closed I think @kg / @steveisok ?

  18. locked and limited conversation to collaborators on May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions