Repository navigation
Description
Description
I have an application I'm testing against .NET 9 daily builds. With the latest SDK and package versions I'm seeing System.AccessViolationException : Attempted to read or write protected memory. This is often an indication that other memory is corrupt. errors in my tests when running on GitHub Actions' macOS arm64 runners.
I have 9 applications I'm doing this with, but I'm only observing this issue with one of them.
Reproduction Steps
- Clone martincostello/costellobot@18966b8
- Run
build.ps1on a macOS arm64 machine.
Expected behavior
The tests all pass.
Actual behavior
Lots of test failures with a stack trace similar to the below:
System.AccessViolationException : Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
at MartinCostello.Costellobot.Infrastructure.IntegrationTests`1.PostWebhookAsync(String event, Object value, String webhookSecret, String delivery) in /_/tests/Costellobot.Tests/Infrastructure/IntegrationTests`1.cs:line 176
at MartinCostello.Costellobot.Handlers.DeploymentStatusHandlerTests.PostWebhookAsync(DeploymentStatusDriver driver, String action) in /_/tests/Costellobot.Tests/Handlers/DeploymentStatusHandlerTests.cs:line 667
at MartinCostello.Costellobot.Handlers.DeploymentStatusHandlerTests.Deployment_Is_Approved_For_Trusted_User_And_Dependency_When_Penultimate_Build_Skipped() in /_/tests/Costellobot.Tests/Handlers/DeploymentStatusHandlerTests.cs:line 128
--- End of stack trace from previous location ---
That corresponds to this code, but it doesn't appear to have been recently changed:
runtime/src/libraries/System.Net.Http/src/System/Net/Http/HttpClient.cs
Lines 520 to 556 in 8f3c687
| async Task<HttpResponseMessage> Core( | |
| HttpRequestMessage request, HttpCompletionOption completionOption, | |
| CancellationTokenSource cts, bool disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) | |
| { | |
| bool telemetryStarted = StartSend(request); | |
| bool responseContentTelemetryStarted = false; | |
| HttpResponseMessage? response = null; | |
| try | |
| { | |
| // Wait for the send request to complete, getting back the response. | |
| response = await base.SendAsync(request, cts.Token).ConfigureAwait(false); | |
| ThrowForNullResponse(response); | |
| // Buffer the response content if we've been asked to. | |
| if (ShouldBufferResponse(completionOption, request)) | |
| { | |
| if (HttpTelemetry.Log.IsEnabled() && telemetryStarted) | |
| { | |
| HttpTelemetry.Log.ResponseContentStart(); | |
| responseContentTelemetryStarted = true; | |
| } | |
| await response.Content.LoadIntoBufferAsync(_maxResponseContentBufferSize, cts.Token).ConfigureAwait(false); | |
| } | |
| return response; | |
| } | |
| catch (Exception e) | |
| { | |
| HandleFailure(e, telemetryStarted, response, cts, originalCancellationToken, pendingRequestsCts); | |
| throw; | |
| } | |
| finally | |
| { | |
| FinishSend(response, cts, disposeCts, telemetryStarted, responseContentTelemetryStarted); | |
| } | |
| } |
Regression?
Yes.
Known Workarounds
None.
Configuration
.NET SDK 9.0.100-preview.4.24265.4
Other information
No response
Activity
dotnet-policy-service commentedon May 16, 2024
Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.
antonfirsov commentedon May 16, 2024
@martincostello any chance you can help us by collecting traces? This could give us some preliminary ideas before someone manages to jump on the issue.
antonfirsov commentedon May 16, 2024
Could this be the root cause?
martincostello commentedon May 16, 2024
Sure, I'll try and do this later today.
I did spot that issue, but it seemed a bit too old to still be an issue in the nightlies?
martincostello commentedon May 16, 2024
Just looked at this - how do I do this exactly when I don't know what the test process' ID will be until after I start the tests?
wfurt commentedon May 16, 2024
I know this annoying. I often add
Console.Readline()to the repro and hit enter after tracing started. Other alternative is to addEventListenerthe the repro itself.wfurt commentedon May 16, 2024
BTW the linked issue blames
libgit2sharp. Do you see same issue on any other platform @martincostello ?martincostello commentedon May 16, 2024
At the moment my repro is just "run dotnet test" - I don't have anything more specific at the moment.
I could maybe add something to the tests to have the tests start monitor itself (if that works?)
I'm only seeing this on macOS, not Windows or Linux, but only in this one project. I'm not specifically using lib2gitsharp anywhere, and if it is being used, I would assume it's from an SDK or something and would/should be present in my other repos I'm testing nightlies with.
martincostello commentedon May 16, 2024
If it helps narrow the search, this has started happening at some point since the 24th April, but all I had to go on was "dotnet test crashes" at that point and I figured it would stabilise at some point. It's only in the last day or so I've noticed it's progressed to not killing the whole process and giving me an exception message and stack trace.
martincostello commentedon May 16, 2024
But that probably correlates more with GitHub Actions runners moving from macOS 12 x64 to macOS 14 arm64, so it was probably broken before then and my build was just on a different arch so I didnt see it before...
martincostello commentedon May 16, 2024
I don't seem to be able to get hold of a
.netracefile as now dotnet test is just crashing again. I do have a dump file I collected a few days ago, but it's ~1.3GB zipped and will contain secrets from my repository that are configured in environment variables.If you let me know what the right secure process to provide the dump file is, I can provide one tomorrow.
15 remaining items
janvorli commentedon Jun 5, 2024
@martincostello could you please share a dump with that crash with me? I am not aware of any instabilities due to the new exception handling in the runtime, so I really want to get to the bottom of this issue. My email is my alias at microsoft.com
martincostello commentedon Jun 5, 2024
@janvorli Just emailed you a link.
janvorli commentedon Jun 5, 2024
@martincostello the dump you have shared with me is somehow broken. I am unable to see the stack trace of the failing thread across a signal handler. Would you be able to capture / share another one?
martincostello commentedon Jun 5, 2024
Sure, I can try - what are the best flags to pass to
dotnet testto get the most useful dump I can for you?janvorli commentedon Jun 5, 2024
I don't have any preference for those. However, instead of letting .NET generate the dump, it might be useful to try to get a dump using the macOS dump collection facility. That means
ulimit -c unlimitedAfter that, running the dotnet test from the same console should produce dump in the /cores directory.
Sometimes, I had problems with dumps collected by our tools in specific cases, so that's why I am suggesting this.
martincostello commentedon Jun 5, 2024
OK - I'm just working on a way to get my CI (I don't have access to any physical mac hardware myself) to upload crash dumps to somewhere securely without putting them into GitHub Actions artifacts first, then once that's working I'll try the extra steps above.
In the meantime, I just had an instance of the tests not crash, but fail with the following stack trace which I've not seen before:
janvorli commentedon Jun 5, 2024
@martincostello I think the issue in the dumps you have shared with me is the issue is most likely a problem already fixed by #101971, so it should be fixed in preview 5. I guess the failures you are getting in preview 5 are likely something else.
It would be great if you could share a dump from a crash with the preview 5 runtime too.
martincostello commentedon Jun 5, 2024
@janvorli Sure - I'll try and get one of the preview 5 ones for you tomorrow.
martincostello commentedon Jun 6, 2024
Not observing any crashes this morning - I'll keep any eye out as my automation updates to newer preview.5 builds daily. If I don't observe any further crashes by the time preview.5 officially ships I'll close this issue.
martincostello commentedon Jun 12, 2024
I can't repro this as of the official preview 5, so I'm going to close this on the basis it must have gotten fixed at some point.
wfurt commentedon Jun 12, 2024
great. Thanks for the confirmation @martincostello