Skip to content

Commit 8e8973c

Browse files
committed
fix: reap zombie process
#88
1 parent 7468d85 commit 8e8973c

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.22.4
55
require (
66
github.com/evalphobia/logrus_sentry v0.8.2
77
github.com/prometheus/client_golang v1.19.1
8+
github.com/ramr/go-reaper v0.2.1
89
github.com/sirupsen/logrus v1.9.3
910
github.com/stretchr/testify v1.8.0
1011
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSz
3030
github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc=
3131
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
3232
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
33+
github.com/ramr/go-reaper v0.2.1 h1:zww+wlQOvTjBZuk1920R/e0GFEb6O7+B0WQLV6dM924=
34+
github.com/ramr/go-reaper v0.2.1/go.mod h1:AVypdzrcCXjSc/JYnlXl8TsB+z84WyFzxWE8Jh0MOJc=
3335
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
3436
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
3537
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=

integration/test.bats

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,15 @@ wait_for() {
101101
@test "it errors on an invalid crontab" {
102102
! run_supercronic -test "${BATS_TEST_DIRNAME}/invalid.crontab"
103103
}
104+
105+
@test "reap zombie process" {
106+
# run in new process namespace
107+
sudo timeout 10s unshare --fork --pid --mount-proc \
108+
${BATS_TEST_DIRNAME}/../supercronic "${BATS_TEST_DIRNAME}/zombie.crontab" &
109+
local pid=$!
110+
sleep 1.5
111+
run bash -c "ps axo pid=,stat=|grep Z"
112+
kill -TERM ${pid}
113+
114+
[[ "$status" -eq 1 ]]
115+
}

integration/zombie.crontab

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* * * * * * * /bin/sleep 1 & exec /bin/sleep 0

main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/aptible/supercronic/log/hook"
1616
"github.com/aptible/supercronic/prometheus_metrics"
1717
"github.com/evalphobia/logrus_sentry"
18+
reaper "github.com/ramr/go-reaper"
1819
"github.com/sirupsen/logrus"
1920
)
2021

@@ -144,6 +145,10 @@ func main() {
144145
}()
145146
}
146147

148+
// Start background reaping of orphaned child processes.
149+
go reaper.Reap()
150+
// _ = reaper.Reap
151+
147152
for {
148153
promMetrics.Reset()
149154

0 commit comments

Comments
 (0)