Skip to content

Segmentation fault 11 on macOS M1 machine running pwsh -c or -file #18998

Closed

Description

Prerequisites

Steps to reproduce

I'm not entirely sure this would be easily reproducible on somebody else's M1. My M1 build machine was working just fine as a Jenkins build agent until I rebooted it this evening. Then my builds started hanging on this node where it first tries to run a PowerShell script. After some debugging, I found out that trying to launch pwsh -c '<command>' causes a segmentation fault. Same with -file. What's odd is that I can start pwsh just fine:

image

Expected behavior

Well, PowerShell should not crash, right?

Actual behavior

I'm seeing a segmentation fault.

Error details

% pwsh -nop -c 'get-date'
zsh: segmentation fault  pwsh -nop -c 'get-date'

Environment data

Name                           Value
----                           -----
PSVersion                      7.3.1
PSEdition                      Core
GitCommitId                    7.3.1
OS                             Darwin 21.6.0 Darwin Kernel Version 21.6.0: Sun Nov  6 23:29:57 PST 2022; root:xnu-8020…
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Also:

 % which pwsh
/usr/local/bin/pwsh

% ls -al /usr/local/bin/pwsh
lrwxr-xr-x  1 root  wheel  38 Jan 20 21:42 /usr/local/bin/pwsh -> /usr/local/microsoft/powershell/7/pwsh

# I also have several versions of the .NET SDK and Runtime installed on this system. That shouldn't matter, right?

% dotnet --info
.NET SDK:
 Version:   7.0.100
 Commit:    e12b7af219

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  12.6
 OS Platform: Darwin
 RID:         osx.12-arm64
 Base Path:   /usr/local/share/dotnet/sdk/7.0.100/

Host:
  Version:      7.0.0
  Architecture: arm64
  Commit:       d099f075e4

.NET SDKs installed:
  6.0.403 [/usr/local/share/dotnet/sdk]
  6.0.404 [/usr/local/share/dotnet/sdk]
  7.0.100 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.12 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.11 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.12 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  x64   [/usr/local/share/dotnet/x64]
    registered at [/etc/dotnet/install_location_x64]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

Visuals

image

Activity

  1. added
    Needs-Triage
    on Jan 21, 2023
  2. rkeithhill-keysight commented on Jan 21, 2023

    @rkeithhill-keysight
    Author

    BTW I tried -nop and still get a seg fault:

    image

  3. rkeithhill-keysight commented on Jan 21, 2023

    @rkeithhill-keysight
    Author

    FYI, downgrading to 7.3.0 has fixed this issue.

  4. added
    Issue-Bug
    WG-DevEx-Portability
    on Jan 23, 2023
  5. bobrozelle commented on Jan 24, 2023

    @bobrozelle

    Same behavior as #18958

  6. rkeithhill-keysight commented on Jan 25, 2023

    @rkeithhill-keysight
    Author

    After 4 days of using 7.3.0 in my Jenkins pipeline (pwsh -c), 7.3.0 is now seg faulting on this command!

    image

    WTF? Steve Lee (@SteveL-MSFT) Any suggestions on a potential workaround - other than uninstalling and installing a different version? That only seems to work for a few days. This is impacting our product devops because we use PowerShell to orchestrate build & test on Mac M1.

  7. rkeithhill-keysight commented on Jan 25, 2023

    @rkeithhill-keysight
    Author

    I removed 7.3.0 and installed 7.3.2 (that must be pretty new) and now pwsh -c works again. Let's see how long 7.3.2 can go before it starts seg faulting. :-)

  8. added
    WG-Maintainers-Build
    and removed
    WG-DevEx-Portability
    on Jan 27, 2023
  9. SteveL-MSFT commented on Jan 27, 2023

    @SteveL-MSFT
    Member

    Unfortunately, not able to repro this. Was able to find two PRs in dotnet/runtime that is related to the area given the stacktrace (thanks!) https://github.com/dotnet/runtime/search?q=issharedbygenericinstantiations&type=issues. Need to look deeper next week.

  10. daxian-dbw commented on Jan 30, 2023

    @daxian-dbw
    Member

    The puzzling part in the report is that the crash doesn't happen consistently -- it started to happen after using 7.3.0 for 4 days.

    The stack trace suggests the crash happened when JIT start profile kicks in, which does early compilation on the methods that were used the last time pwsh going through the same code path -- in this case for pwsh -c or pwsh -file, non-interactive execution (ProfileOptimization.StartProfile("StartupProfileData-NonInteractive")).

    So, it makes sense that running pwsh itself works, because that will be interactive execution, which will be using a different profile: ProfileOptimization.StartProfile("StartupProfileData-Interactive").

    Keith Hill (@rkeithhill-keysight) Can you please try the following when pwsh -c "get-date" results in segment fault, and see if the next run of pwsh -c works:

    • remove the StartupProfileData-NonInteractive file under /home/<user-name>/.cache/powershell

    Having this file removed will make CLR not attempt to do the early method compilation, so if this theory is correct, the next run of pwsh -c "get-date" should work again. If you can verify this is the case, I will open an issue on this in the .NET repo.

  11. rkeithhill-keysight commented on Jan 30, 2023

    @rkeithhill-keysight
    Author

    Dongbo Wang (@daxian-dbw) Yes, I'll give that a try if/when we encounter the seg fault again.

  12. daxian-dbw commented on Feb 7, 2023

    @daxian-dbw
    Member

    .NET issue opened: dotnet/runtime#81799

  13. removed
    Needs-Triage
    on Feb 8, 2023
  14. rkeithhill-keysight commented on Jun 3, 2023

    @rkeithhill-keysight
    Author

    And now 7.3.2 has started to gen seg faults ~5 1/2 months after installing 7.3.2. 🤷‍♂️

    I tried Dongbo Wang (@daxian-dbw) suggestion to remove the StartupProfileData-NonInteractive file and that fixes it. Not sure how long the fix will last but my CI/CD builds are running again on this M1 mini.

  15. daxian-dbw commented on Jun 5, 2023

    @daxian-dbw
    Member

    Keith Hill (@rkeithhill-keysight) The root cause is in .NET, see dotnet/runtime#81799. Please try collecting a dump when the crash happens, and share the dump in the .NET issue -- they need a dump to further investigate the issue (see dotnet/runtime#81799 (comment)).

  16. rkeithhill-keysight commented on Jun 5, 2023

    @rkeithhill-keysight
    Author

    I read the .NET issue after I had fixed it. 🤦‍♂️ Next time this happens, I'll collect a dump and post it there.

  17. GordonVi commented on Jul 12, 2023

    @GordonVi

    Just ran into this after updating powershell on CentOS:

    pwsh 7.3.5 (old was 7.3.4)

    commands:

    update powershell

    sudo yum update powershell

    Set permissions for powershell to run commands

    sudo setcap cap_net_raw=eip /opt/microsoft/powershell/7/pwsh # real binary, not symlink

    rename offending config file

    mv /home/user/.cache/powershell/StartupProfileData-NonInteractive /home/user/.cache/powershell/StartupProfileData-NonInteractive.disable

  18. added
    Resolution-No Activity
    on Jan 9, 2024
  19. rkeithhill-keysight commented on Sep 20, 2024

    @rkeithhill-keysight
    Author

    FWIW it appears this issue was fixed in .NET. Here's the .NET issue and here's the PR that fixes it.

  20. pregress commented on Feb 25, 2025

    @pregress

    Can this be re-opend please?
    I had the same issue on 7.5.0.

    Disabling the file: mv ~/.cache/powershell/StartupProfileData-NonInteractive ~/.cache/powershell/StartupProfileData-NonInteractive.disable solved it, as suggested by Gordon Virasawmi (@GordonVi)

    $psversiontable
    
    Name                           Value
    ----                           -----
    PSVersion                      7.5.0
    PSEdition                      Core
    GitCommitId                    7.5.0
    OS                             Ubuntu 22.04.5 LTS
    Platform                       Unix
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1
    WSManStackVersion              3.0
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugResolution-No ActivityWG-Maintainers-Build

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions