mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-23 20:17:03 +01:00
Prevent dangling GetAttribute calls (#18754)
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>
This commit is contained in:
parent
5348e198db
commit
4482f62a26
3 changed files with 13 additions and 7 deletions
|
@ -185,7 +185,8 @@ func (c *CheckAttributeReader) Init(ctx context.Context) error {
|
||||||
// Run run cmd
|
// Run run cmd
|
||||||
func (c *CheckAttributeReader) Run() error {
|
func (c *CheckAttributeReader) Run() error {
|
||||||
defer func() {
|
defer func() {
|
||||||
_ = c.Close()
|
_ = c.stdinReader.Close()
|
||||||
|
_ = c.stdOut.Close()
|
||||||
}()
|
}()
|
||||||
stdErr := new(bytes.Buffer)
|
stdErr := new(bytes.Buffer)
|
||||||
err := c.cmd.RunWithContext(&RunContext{
|
err := c.cmd.RunWithContext(&RunContext{
|
||||||
|
@ -196,14 +197,17 @@ func (c *CheckAttributeReader) Run() error {
|
||||||
Stdout: c.stdOut,
|
Stdout: c.stdOut,
|
||||||
Stderr: stdErr,
|
Stderr: stdErr,
|
||||||
PipelineFunc: func(_ context.Context, _ context.CancelFunc) error {
|
PipelineFunc: func(_ context.Context, _ context.CancelFunc) error {
|
||||||
|
select {
|
||||||
|
case <-c.running:
|
||||||
|
default:
|
||||||
close(c.running)
|
close(c.running)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil && c.ctx.Err() != nil && err.Error() != "signal: killed" {
|
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 fmt.Errorf("failed to run attr-check. Error: %w\nStderr: %s", err, stdErr.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,10 +247,8 @@ func (c *CheckAttributeReader) CheckPath(path string) (rs map[string]string, err
|
||||||
|
|
||||||
// Close close pip after use
|
// Close close pip after use
|
||||||
func (c *CheckAttributeReader) Close() error {
|
func (c *CheckAttributeReader) Close() error {
|
||||||
err := c.stdinWriter.Close()
|
|
||||||
_ = c.stdinReader.Close()
|
|
||||||
_ = c.stdOut.Close()
|
|
||||||
c.cancel()
|
c.cancel()
|
||||||
|
err := c.stdinWriter.Close()
|
||||||
select {
|
select {
|
||||||
case <-c.running:
|
case <-c.running:
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -88,7 +88,10 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
defer cancel()
|
defer func() {
|
||||||
|
_ = checker.Close()
|
||||||
|
cancel()
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1422,6 +1422,7 @@ func GetDiff(gitRepo *git.Repository, opts *DiffOptions, files ...string) (*Diff
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
|
_ = checker.Close()
|
||||||
cancel()
|
cancel()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue