Skip to content

Commit 7b2dd03

Browse files
zeripathlunny6543
authored andcommitted
Prevent intermittent race in attribute reader close (go-gitea#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 <[email protected]> Co-authored-by: Lunny Xiao <[email protected]> Co-authored-by: 6543 <[email protected]>
1 parent 2a953c7 commit 7b2dd03

File tree

1 file changed

+1
-16
lines changed

1 file changed

+1
-16
lines changed

modules/git/repo_attribute.go

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,10 @@ type CheckAttributeReader struct {
124124
env []string
125125
ctx context.Context
126126
cancel context.CancelFunc
127-
running chan struct{}
128127
}
129128

130129
// Init initializes the cmd
131130
func (c *CheckAttributeReader) Init(ctx context.Context) error {
132-
c.running = make(chan struct{})
133131
cmdArgs := []string{"check-attr", "--stdin", "-z"}
134132

135133
if len(c.IndexFile) > 0 && CheckGitVersionAtLeast("1.7.8") == nil {
@@ -194,14 +192,6 @@ func (c *CheckAttributeReader) Run() error {
194192
Stdin: c.stdinReader,
195193
Stdout: c.stdOut,
196194
Stderr: stdErr,
197-
PipelineFunc: func(_ context.Context, _ context.CancelFunc) error {
198-
select {
199-
case <-c.running:
200-
default:
201-
close(c.running)
202-
}
203-
return nil
204-
},
205195
})
206196
if err != nil && // If there is an error we need to return but:
207197
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
222212
select {
223213
case <-c.ctx.Done():
224214
return nil, c.ctx.Err()
225-
case <-c.running:
215+
default:
226216
}
227217

228218
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
249239
func (c *CheckAttributeReader) Close() error {
250240
c.cancel()
251241
err := c.stdinWriter.Close()
252-
select {
253-
case <-c.running:
254-
default:
255-
close(c.running)
256-
}
257242
return err
258243
}
259244

0 commit comments

Comments
 (0)