fix: prevent NullReferenceException in Histories async operations#2289
Closed
gadfly3173 wants to merge 1 commit intosourcegit-scm:developfrom
Closed
fix: prevent NullReferenceException in Histories async operations#2289gadfly3173 wants to merge 1 commit intosourcegit-scm:developfrom
gadfly3173 wants to merge 1 commit intosourcegit-scm:developfrom
Conversation
Add null checks for _repo in Histories methods to prevent crashes when Repository is closed while async operations are still pending. Bug Cause: When Repository.Close() is called, Histories.Dispose() sets _repo to null. If an async operation (e.g., CheckoutBranchByDecoratorAsync triggered by double-clicking a branch icon) is executing concurrently, it may access the now-null _repo reference, causing NullReferenceException. Stack Trace: ```log System.NullReferenceException: Object reference not set to an instance of an object. at SourceGit.ViewModels.Repository.<CheckoutBranchAsync>d__192.MoveNext() + 0x169 --- End of stack trace from previous location --- at SourceGit.ViewModels.Histories.<CheckoutBranchByDecoratorAsync>d__48.MoveNext() + 0x57 --- End of stack trace from previous location --- at SourceGit.Views.Histories.<OnCommitListDoubleTapped>d__34.MoveNext() + 0x5a --- End of stack trace from previous location --- at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__124_0(Object state) + 0x1a at Avalonia.Threading.SendOrPostCallbackDispatcherOperation.InvokeCore() + 0x19a at Avalonia.Threading.DispatcherOperation.Execute() + 0x4a at Avalonia.Threading.Dispatcher.ExecuteJob(DispatcherOperation) + 0x78 at Avalonia.Threading.Dispatcher.ExecuteJobsCore(Boolean) + 0x387 at Avalonia.Win32.Win32Platform.WndProc(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam) + 0x58 at SourceGit!<BaseAddress>+0x1166c9a ```
Collaborator
|
It's not just about I believe the only solution to such problems is that when there is a action still running, the |
love-linger
added a commit
that referenced
this pull request
Apr 21, 2026
…still running (#2289) Signed-off-by: leo <longshuang@msn.cn>
Collaborator
|
I've pushed my fix for this bug |
love-linger
added a commit
that referenced
this pull request
Apr 21, 2026
…still running (#2289) - It's not necessary to implement `IDisposable` interface for class that only contains managed resources - Do not clear fields of `Repository` and let system GC handle it Signed-off-by: leo <longshuang@msn.cn>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add null checks for _repo in Histories methods to prevent crashes when Repository is closed while async operations are still pending.
Bug Cause:
When Repository.Close() is called, Histories.Dispose() sets _repo to null. If an async operation (e.g., CheckoutBranchByDecoratorAsync triggered by double-clicking a branch icon) is executing concurrently, it may access the now-null _repo reference, causing NullReferenceException.
Stack Trace: