Skip to content

Ignore Sync errors on pipes when doing CheckAttributeReader.CheckPath, fix the hang of git cat-file #17096

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

Merged
merged 8 commits into from
Sep 20, 2021
12 changes: 6 additions & 6 deletions modules/git/repo_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,15 @@ func (c *CheckAttributeReader) Init(ctx context.Context) error {

if len(c.IndexFile) > 0 && CheckGitVersionAtLeast("1.7.8") == nil {
cmdArgs = append(cmdArgs, "--cached")
c.env = []string{"GIT_INDEX_FILE=" + c.IndexFile}
c.env = append(c.env, "GIT_INDEX_FILE="+c.IndexFile)
}

if len(c.WorkTree) > 0 && CheckGitVersionAtLeast("1.7.8") == nil {
c.env = []string{"GIT_WORK_TREE=" + c.WorkTree}
c.env = append(c.env, "GIT_WORK_TREE="+c.WorkTree)
}

c.env = append(c.env, "GIT_FLUSH=1")

if len(c.Attributes) > 0 {
cmdArgs = append(cmdArgs, c.Attributes...)
cmdArgs = append(cmdArgs, "--")
Expand Down Expand Up @@ -182,10 +184,8 @@ func (c *CheckAttributeReader) CheckPath(path string) (map[string]string, error)
return nil, err
}

if err := c.stdinWriter.Sync(); err != nil {
defer c.cancel()
return nil, err
}
// not necessary to call Sync on pipe. And it usually results in error: "sync |1: invalid argument"
_ = c.stdinWriter.Sync()

rs := make(map[string]string)
for range c.Attributes {
Expand Down