RepositoryStatus sometimes crashes with an AccessViolationException
See original GitHub issueWe’ve noticed that the GitHub Extension for Visual Studio has been crashing with an AccessViolationException
. This often happens when a user previews a PR and the extension calls RetrieveStatus
. This exception occurs randomly and is thrown by the git_status_list_new
method.
This exception is most easily reproduced using 0.24
or 0.25.0-preview-0033
, but it does also happen with 0.23.1
(but I haven’t seen it using the repro below).
How to reproduce
- Clone
https://github.com/github/VisualStudio.git
toC:\source\github.com\github\VisualStudio\
. - Compile and run the following code in
Release
configuration using LibGit2Sharpv0.24
:
static void Main(string[] args)
{
var path = @"C:\source\github.com\github\VisualStudio";
for (int count = 0; count < 1000; count++)
{
var status = new Repository(path).RetrieveStatus();
Console.WriteLine(count + ": " + status.IsDirty);
}
}
I tried to create a standalone app, but wasn’t able to trigger it with a very simple repo. I’m using the github\VisualStudio
one because I’m most familiar it, but it does this with many others as well.
What to expect
The most common exception is as follows:
System.AccessViolationException was unhandled
HResult=-2147467261
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source=LibGit2Sharp
StackTrace:
at LibGit2Sharp.Core.NativeMethods.git_status_list_new(git_status_list*& git_status_list, git_repository* repo, GitStatusOptions options)
at LibGit2Sharp.Core.Proxy.git_status_list_new(RepositoryHandle repo, GitStatusOptions options) in C:\projects\libgit2sharp\LibGit2Sharp\Core\Proxy.cs:line 2931
at LibGit2Sharp.RepositoryStatus..ctor(Repository repo, StatusOptions options) in C:\projects\libgit2sharp\LibGit2Sharp\RepositoryStatus.cs:line 60
at LibGit2Sharp.RepositoryExtensions.RetrieveStatus(IRepository repository) in C:\projects\libgit2sharp\LibGit2Sharp\RepositoryExtensions.cs:line 696
at Libgit2Repro.Program.Main(String[] args) in c:\users\passp\onedrive\documents\visual studio 2015\Projects\Libgit2Repro\Libgit2Repro\Program.cs:line 20
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
But sometimes NotFoundExceptions
are thrown as well.
Related issues / PRs
- Find out why / when LibGit2Sharp is crashing: github/VisualStudio#1315
- GitHub extension crashes when viewing pull requests: github/VisualStudio#1306
- “could not find [file] to open” exception thrown when opening a PR: github/VisualStudio#1326
- Move from LibGit2Sharp v0.24.0 to v0.23.1: github/VisualStudio#1316
- Add using to avoid crash in Release mode: github/VisualStudio#1311
Issue Analytics
- State:
- Created 6 years ago
- Comments:13 (7 by maintainers)
Top Results From Across the Web
How to handle System.AccessViolationException?
I'm using an external C library in my program coded in C++/CLI with the .NET framework 4. Sometimes the lib crashes and I...
Read more >What do you do when Unreal Editor crashes? - YouTube
... the error 02:09 - Where: Getting the callstack 02:53 - Engine PDBs 04:25 - When: Reproducing the crash 05:37 - Who: Asking...
Read more >[Help] Every .NET application crashes ...
Taking a look in the event viewer, where I saw a bunch of .NET runtime related errors, showed me AccessViolationExceptions. I'm having this ......
Read more >Crashing and BSODs (Access violation errors everywhere)
Sometimes with BSOD, forcing a hard reboot, sometimes just crash to desktop, same game can crash both ways (either BSOD or normal CTD)....
Read more >AccessViolationException in System.Web - Microsoft Q&A
I am occassionally (every few hours or so) seeing crashes leading to entries in the event viewer saying "A process serving application pool...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve the same problem with 0.26 and 0.27 preview:
Just seen https://github.com/libgit2/libgit2sharp/issues/1886 … my issue also started after an update of VS2019 to 16.10.1. (This update also contained the latest .NET 5 SDK 5.0.7)
And stepping through with debugger also always works - seems to prevent the repository object GC as well…