1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Ensure BlameReaders close at end of request (#12102) (#12103)

Backport #12102

this was thought to be due to timeouts, however on closer look this
appears to be due to the Close() function of the BlameReader hanging
with a blocked stdout pipe.

This PR fixes this Close function to:

* Cancel the context of the cmd
* Close the StdoutReader - ensuring that the output pipe is closed

Further it makes the context of the `git blame` command a child of the
request context - ensuring that even if Close() is not called, on
cancellation of the Request the blame is command will also be cancelled.

Fixes #11716
Closes #11727

Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
zeripath
2020-07-01 16:43:25 +01:00
committed by GitHub
parent df13fc8818
commit 20c2bdf86b
3 changed files with 19 additions and 8 deletions

View File

@@ -141,7 +141,13 @@ func RefBlame(ctx *context.Context) {
ctx.Data["FileSize"] = blob.Size()
ctx.Data["FileName"] = blob.Name()
blameReader, err := git.CreateBlameReader(models.RepoPath(userName, repoName), commitID, fileName)
ctx.Data["NumLines"], err = blob.GetBlobLineCount()
if err != nil {
ctx.NotFound("GetBlobLineCount", err)
return
}
blameReader, err := git.CreateBlameReader(ctx.Req.Context(), models.RepoPath(userName, repoName), commitID, fileName)
if err != nil {
ctx.NotFound("CreateBlameReader", err)
return