Skip to content

Conversation

mstv
Copy link
Member

@mstv mstv commented Nov 27, 2024

Fixes #12055

Proposed changes

  • fix(RevisionReader.GetRevision): Avoid hang in StandardError.ReadToEnd on lengthy StandardOutput
  • The other usages of GitCommandRunner.RunDetached are not affected as they do not read StandardError at all.
  • Extract GetRevisionAsync as proposed by Roslyn analyzer

Screenshots

N/A

Test methodology

  • manual

Test environment(s)

https://github.com/mstv/test_lfs/tree/test_long_commit_body

Merge strategy

I agree that the maintainer squash merge this PR (if the commit message is clear).


✒️ I contribute this code under The Developer Certificate of Origin.

@mstv mstv self-assigned this Nov 27, 2024
Copy link
Member

@gerhardol gerhardol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 looks reasonable

Copy link
Member

@RussKie RussKie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -184,13 +201,21 @@ public IReadOnlyCollection<GitRevision> GetRevisionsFromRange(string olderCommit
Debug.WriteLine($"git {arguments}");
#endif
using IProcess process = _module.GitCommandRunner.RunDetached(cancellationToken, arguments, redirectOutput: true, outputEncoding: null);
string errorOutput = process.StandardError.ReadToEnd();

// StandardError.ReadToEnd[Async] hangs if lengthy StandardOutput is not consumed in parallel. So, buffer the StandardOutput
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// StandardError.ReadToEnd[Async] hangs if lengthy StandardOutput is not consumed in parallel. So, buffer the StandardOutput
// StandardError.ReadToEnd[Async] may become unresponsive, if lengthy StandardOutput is not consumed in parallel. So, buffer the StandardOutput.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

string errorOutput = process.StandardError.ReadToEnd();

// StandardError.ReadToEnd[Async] hangs if lengthy StandardOutput is not consumed in parallel. So, buffer the StandardOutput
MemoryStream standardOutputBuffer = new();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MemoryStream standardOutputBuffer = new();
using MemoryStream standardOutputBuffer = new();

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@mstv mstv force-pushed the fix/12055_detached_process_hang branch from 126043a to 51dd817 Compare December 3, 2024 22:52
@mstv mstv merged commit 51dd817 into gitextensions:master Dec 3, 2024
3 of 4 checks passed
@mstv mstv deleted the fix/12055_detached_process_hang branch December 3, 2024 22:53
@mstv mstv added this to the v5.2 milestone Jan 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

After clicking on "Created new branch here..." application hangs forever
3 participants