Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent intermittent race in attribute reader close #19537

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions modules/git/repo_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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
}

Expand Down