Skip to content

Commit

Permalink
fix: process resources are not released (#66)
Browse files Browse the repository at this point in the history
Fixed #65
  • Loading branch information
k3rn31 committed Jul 27, 2022
1 parent a19ff06 commit 3ca6883
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion pkg/mutator/mutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@ func (mu *Mutator) runTests() mutant.Status {
defer cancel()
cmd := mu.execContext(ctx, "go", mu.getTestArgs()...)

err := cmd.Run() //nolint:ifshort
rel, err := run(cmd)
defer rel()

if errors.Is(ctx.Err(), context.DeadlineExceeded) {
return mutant.TimedOut
}
Expand All @@ -265,6 +267,20 @@ func (mu *Mutator) runTests() mutant.Status {
return mutant.Lived
}

func run(cmd *exec.Cmd) (func(), error) {
if err := cmd.Run(); err != nil {

return func() {}, err
}

return func() {
err := cmd.Process.Release()
if err != nil {
_ = cmd.Process.Kill()
}
}, nil
}

func (mu *Mutator) getTestArgs() []string {
args := []string{"test"}
if mu.buildTags != "" {
Expand Down

0 comments on commit 3ca6883

Please # to comment.