Skip to content

Commit

Permalink
Merge pull request #11 from FortnoxAB/reapzombies
Browse files Browse the repository at this point in the history
Fix problem with defunced git commands from renovate-bot
  • Loading branch information
jonaz authored Nov 28, 2024
2 parents 6fcc0bc + c6b9eb5 commit 5424751
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
28 changes: 27 additions & 1 deletion pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ package agent

import (
"context"
"errors"
"fmt"
"os"
"os/signal"
"strings"
"sync"
"syscall"
"time"

"github.com/fortnoxab/renovator/pkg/command"
Expand Down Expand Up @@ -48,7 +52,7 @@ func NewAgentFromContext(cCtx *cli.Context) (*Agent, error) {
}

func (a *Agent) Run(ctx context.Context) {

ZombieReaper()
reposToProcess := make(chan string)

wg := &sync.WaitGroup{}
Expand Down Expand Up @@ -104,3 +108,25 @@ func (a *Agent) Run(ctx context.Context) {
}
wg.Wait()
}

func ZombieReaper() {
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGCHLD)

go func() {
for range signals {
for {
var wstatus syscall.WaitStatus
pid, err := syscall.Wait4(-1, &wstatus, 0, nil)
if errors.Is(err, syscall.ECHILD) {
break
}
if err != nil {
logrus.Errorf("error waiting for child %d: %s", pid, err)
continue
}
logrus.Debugf("reaped zombie %d %d", pid, wstatus)
}
}
}()
}
3 changes: 2 additions & 1 deletion pkg/master/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"sync"

"github.com/fortnoxab/renovator/pkg/agent"
"github.com/fortnoxab/renovator/pkg/command"
"github.com/fortnoxab/renovator/pkg/kafka"
"github.com/fortnoxab/renovator/pkg/leaderelect"
Expand Down Expand Up @@ -63,10 +64,10 @@ func NewMasterFromContext(cCtx *cli.Context) (*Master, error) {
}

func (m *Master) Run(ctx context.Context) error {

if m.CronSchedule == nil {
return doRun(ctx, m.Candidate, m.RedisClient, m.Renovator, m.LeaderElect)
}
agent.ZombieReaper()

if m.RunFirstTime {
logrus.Info("running due to --run-first-time")
Expand Down

0 comments on commit 5424751

Please sign in to comment.