aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git/blame_test.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2020-07-01 14:01:17 +0100
committerGitHub <noreply@github.com>2020-07-01 14:01:17 +0100
commit858c35b73184aa94242076d417ad09a74c55aebf (patch)
tree50bed5c8733f461266f1a9a3984cad21ffaf35b6 /modules/git/blame_test.go
parent8f489131f32e45b0848475848c22405e8de6f5ff (diff)
downloadgitea-858c35b73184aa94242076d417ad09a74c55aebf.tar.gz
gitea-858c35b73184aa94242076d417ad09a74c55aebf.zip
Ensure BlameReaders close at end of request (#12102)
#11716 reports multiple git blame processes hanging around 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>
Diffstat (limited to 'modules/git/blame_test.go')
-rw-r--r--modules/git/blame_test.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/modules/git/blame_test.go b/modules/git/blame_test.go
index 1752312d81..734d63ee14 100644
--- a/modules/git/blame_test.go
+++ b/modules/git/blame_test.go
@@ -5,6 +5,7 @@
package git
import (
+ "context"
"io/ioutil"
"testing"
@@ -93,8 +94,10 @@ func TestReadingBlameOutput(t *testing.T) {
if _, err = tempFile.WriteString(exampleBlame); err != nil {
panic(err)
}
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
- blameReader, err := createBlameReader("", "cat", tempFile.Name())
+ blameReader, err := createBlameReader(ctx, "", "cat", tempFile.Name())
if err != nil {
panic(err)
}