diff options
author | zeripath <art27@cantab.net> | 2022-02-14 20:27:55 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-14 15:27:55 -0500 |
commit | 7ebc3da7cbb69aeb42fdd9498bf2c068bc27b9b4 (patch) | |
tree | 8442be6c5b8ba115dd5eda2c925ea25322c771fd /modules/git/repo_attribute.go | |
parent | 2e36ba0a009624adb55812988e702bbb7beb69f2 (diff) | |
download | gitea-7ebc3da7cbb69aeb42fdd9498bf2c068bc27b9b4.tar.gz gitea-7ebc3da7cbb69aeb42fdd9498bf2c068bc27b9b4.zip |
Prevent dangling GetAttribute calls (#18754) (#18755)
* Prevent dangling GetAttribute calls
It appears possible that there could be a hang due to unread data from the
repo-attribute command pipes. This PR simply closes these during the defer.
Signed-off-by: Andrew Thornton <art27@cantab.net>
* move close into the defer
Signed-off-by: Andrew Thornton <art27@cantab.net>
* lets try again
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules/git/repo_attribute.go')
-rw-r--r-- | modules/git/repo_attribute.go | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/modules/git/repo_attribute.go b/modules/git/repo_attribute.go index 0bb550bb4b..3f6f8943a9 100644 --- a/modules/git/repo_attribute.go +++ b/modules/git/repo_attribute.go @@ -87,7 +87,7 @@ func (repo *Repository) CheckAttribute(opts CheckAttributeOpts) (map[string]map[ return nil, fmt.Errorf("wrong number of fields in return from check-attr") } - var name2attribute2info = make(map[string]map[string]string) + name2attribute2info := make(map[string]map[string]string) for i := 0; i < (len(fields) / 3); i++ { filename := string(fields[3*i]) @@ -179,17 +179,21 @@ func (c *CheckAttributeReader) Init(ctx context.Context) error { // Run run cmd func (c *CheckAttributeReader) Run() error { defer func() { - _ = c.Close() + _ = c.stdinReader.Close() + _ = c.stdOut.Close() }() stdErr := new(bytes.Buffer) err := c.cmd.RunInDirTimeoutEnvFullPipelineFunc(c.env, -1, c.Repo.Path, c.stdOut, stdErr, c.stdinReader, func(_ context.Context, _ context.CancelFunc) error { - close(c.running) + select { + case <-c.running: + default: + close(c.running) + } return nil }) if err != nil && c.ctx.Err() != nil && err.Error() != "signal: killed" { return fmt.Errorf("failed to run attr-check. Error: %w\nStderr: %s", err, stdErr.String()) } - return nil } @@ -229,10 +233,8 @@ func (c *CheckAttributeReader) CheckPath(path string) (rs map[string]string, err // Close close pip after use func (c *CheckAttributeReader) Close() error { - err := c.stdinWriter.Close() - _ = c.stdinReader.Close() - _ = c.stdOut.Close() c.cancel() + err := c.stdinWriter.Close() select { case <-c.running: default: |