diff options
author | zeripath <art27@cantab.net> | 2022-04-28 04:19:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-28 11:19:33 +0800 |
commit | 332b2ecd214a79b49f3798f4f27fe02b23a17bf8 (patch) | |
tree | 7e1dfb1cee7387a700a44e32d2eb1ad88178fb9f | |
parent | ca4b920bbcbc803ef6e3d1deffefab3ab88cb1c7 (diff) | |
download | gitea-332b2ecd214a79b49f3798f4f27fe02b23a17bf8.tar.gz gitea-332b2ecd214a79b49f3798f4f27fe02b23a17bf8.zip |
Prevent intermittent race in attribute reader close (#19537)
There is a potential rare race possible whereby the c.running channel could
be closed twice. Looking at the code I do not see a need for this c.running
channel and therefore I think we can remove this. (I think the c.running
might have been some attempt to prevent a hang but the use of os.Pipes should
prevent that.)
Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: 6543 <6543@obermui.de>
-rw-r--r-- | modules/git/repo_attribute.go | 17 |
1 files changed, 1 insertions, 16 deletions
diff --git a/modules/git/repo_attribute.go b/modules/git/repo_attribute.go index 6481474a96..a18c80c3f1 100644 --- a/modules/git/repo_attribute.go +++ b/modules/git/repo_attribute.go @@ -124,12 +124,10 @@ type CheckAttributeReader struct { env []string ctx context.Context cancel context.CancelFunc - running chan struct{} } // Init initializes the cmd func (c *CheckAttributeReader) Init(ctx context.Context) error { - c.running = make(chan struct{}) cmdArgs := []string{"check-attr", "--stdin", "-z"} if len(c.IndexFile) > 0 && CheckGitVersionAtLeast("1.7.8") == nil { @@ -194,14 +192,6 @@ func (c *CheckAttributeReader) Run() error { Stdin: c.stdinReader, Stdout: c.stdOut, Stderr: stdErr, - PipelineFunc: func(_ context.Context, _ context.CancelFunc) error { - select { - case <-c.running: - default: - close(c.running) - } - return nil - }, }) if err != nil && // If there is an error we need to return but: c.ctx.Err() != err && // 1. Ignore the context error if the context is cancelled or exceeds the deadline (RunWithContext could return c.ctx.Err() which is Canceled or DeadlineExceeded) @@ -222,7 +212,7 @@ func (c *CheckAttributeReader) CheckPath(path string) (rs map[string]string, err select { case <-c.ctx.Done(): return nil, c.ctx.Err() - case <-c.running: + default: } if _, err = c.stdinWriter.Write([]byte(path + "\x00")); err != nil { @@ -249,11 +239,6 @@ func (c *CheckAttributeReader) CheckPath(path string) (rs map[string]string, err func (c *CheckAttributeReader) Close() error { c.cancel() err := c.stdinWriter.Close() - select { - case <-c.running: - default: - close(c.running) - } return err } |