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

[.NET6 fix port] AccessViolationException with PublishSingleFile #81181

Closed
marek22 opened this issue Jan 25, 2023 · 5 comments
Closed

[.NET6 fix port] AccessViolationException with PublishSingleFile #81181

marek22 opened this issue Jan 25, 2023 · 5 comments

Comments

@marek22
Copy link

marek22 commented Jan 25, 2023

Description

I am requesting a port of the fix for issue #62145 from PR #74389 for .NET 6 since it is the LTS release. I confirmed that changing from .NET 6 to .NET 7 fixes the problem in a test application but cannot migrate all applications to .NET 7 at this time.

This bug is impacting me specifically when using the New Relic Agent in Docker when targeting .NET 6 and using the .NET 6 runtime image (mcr.microsoft.com/dotnet/runtime:6.0) but goes away when targeting .NET 7 and using the .NET 7 runtime image (mcr.microsoft.com/dotnet/runtime:7.0). When running containers in the 6.0 configuration it will sporadically throw the AccessViolationException (about 1-2% of the time) but never on the 7.0 configuration.

Reproduction Steps

I copied the reproduction example from the previous issue and tested it in both .NET 6 and .NET 7 by just changing the TargetFramework from net6.0 to net7.0 and was able to reproduce the issue only in .NET 6 using the most recent (6.0.13) runtime with the fix working in .NET 7.

using System.Diagnostics.Tracing;

namespace SegFaultTest
{
    internal class Program
    {
        static void Main(string[] args)
        {
            EventListener eventListener = new MyEventListener();

            Console.WriteLine("Press any key to abort...");

            // Do some stuff
            for (int i = 1; i < int.MaxValue; i++)
            {
                if (Console.KeyAvailable)
                {
                    break;
                }

                string a = new('a', i % 10000);
            }

            Console.WriteLine("Done.");
        }
    }

    internal class MyEventListener : EventListener
    {
        protected override void OnEventSourceCreated(EventSource eventSource)
        {
            if (eventSource.Name.Equals("Microsoft-Windows-DotNETRuntime", StringComparison.Ordinal))
            {
                EnableEvents(eventSource, EventLevel.Informational, (EventKeywords)1);
            }
        }

        protected override void OnEventWritten(EventWrittenEventArgs eventData)
        {
            Console.WriteLine($"Event written {eventData.EventId,3} {eventData.EventName ?? string.Empty}");
        }
    }
}

Expected behavior

No AccessViolationException thrown

Actual behavior

AccessViolationException is thrown

Regression?

No response

Known Workarounds

Upgrade to .NET 7

Configuration

Project file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
	<SelfContained>true</SelfContained>
	<PublishSingleFile>True</PublishSingleFile>
	<PublishReadyToRun>False</PublishReadyToRun>
	<RuntimeIdentifier>win-x64</RuntimeIdentifier>
  </PropertyGroup>

</Project>

Other information

New Relic issue related to this: link
Original dotnet issue: link
Original PR for .NET 7: link

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jan 25, 2023
@marek22
Copy link
Author

marek22 commented Jan 25, 2023

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

I don't seem to be able to add a label but it should probably be labeled as area-Single-File like the original

@ghost
Copy link

ghost commented Jan 25, 2023

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

Issue Details

Description

I am requesting a port of the fix for issue #62145 from PR #74389 for .NET 6 since it is the LTS release. I confirmed that changing from .NET 6 to .NET 7 fixes the problem in a test application but cannot migrate all applications to .NET 7 at this time.

This bug is impacting me specifically when using the New Relic Agent in Docker when targeting .NET 6 and using the .NET 6 runtime image (mcr.microsoft.com/dotnet/runtime:6.0) but goes away when targeting .NET 7 and using the .NET 7 runtime image (mcr.microsoft.com/dotnet/runtime:7.0). When running containers in the 6.0 configuration it will sporadically throw the AccessViolationException (about 1-2% of the time) but never on the 7.0 configuration.

Reproduction Steps

I copied the reproduction example from the previous issue and tested it in both .NET 6 and .NET 7 by just changing the TargetFramework from net6.0 to net7.0 and was able to reproduce the issue only in .NET 6 using the most recent (6.0.13) runtime with the fix working in .NET 7.

using System.Diagnostics.Tracing;

namespace SegFaultTest
{
    internal class Program
    {
        static void Main(string[] args)
        {
            EventListener eventListener = new MyEventListener();

            Console.WriteLine("Press any key to abort...");

            // Do some stuff
            for (int i = 1; i < int.MaxValue; i++)
            {
                if (Console.KeyAvailable)
                {
                    break;
                }

                string a = new('a', i % 10000);
            }

            Console.WriteLine("Done.");
        }
    }

    internal class MyEventListener : EventListener
    {
        protected override void OnEventSourceCreated(EventSource eventSource)
        {
            if (eventSource.Name.Equals("Microsoft-Windows-DotNETRuntime", StringComparison.Ordinal))
            {
                EnableEvents(eventSource, EventLevel.Informational, (EventKeywords)1);
            }
        }

        protected override void OnEventWritten(EventWrittenEventArgs eventData)
        {
            Console.WriteLine($"Event written {eventData.EventId,3} {eventData.EventName ?? string.Empty}");
        }
    }
}

Expected behavior

No AccessViolationException thrown

Actual behavior

AccessViolationException is thrown

Regression?

No response

Known Workarounds

Upgrade to .NET 7

Configuration

Project file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
	<SelfContained>true</SelfContained>
	<PublishSingleFile>False</PublishSingleFile>
	<PublishReadyToRun>False</PublishReadyToRun>
	<RuntimeIdentifier>win-x64</RuntimeIdentifier>
  </PropertyGroup>

</Project>

Other information

New Relic issue related to this: link
Original dotnet issue: link
Original PR for .NET 7: link

Author: marek22
Assignees: -
Labels:

area-Single-File, untriaged

Milestone: -

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jan 26, 2023
@marek22
Copy link
Author

marek22 commented Jan 26, 2023

Thanks, @VSadov for working on this so quickly! I really appreciate all the hard work from you and your team!

@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Feb 8, 2023
@agocke agocke added this to AppModel Sep 18, 2023
@agocke
Copy link
Member

agocke commented Jan 30, 2024

Fixed by #81238

@agocke agocke closed this as completed Jan 30, 2024
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Jan 30, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

No branches or pull requests

3 participants