webdevops / go-crond

:alarm_clock: Cron daemon written in golang (for eg. usage in docker images)
GNU General Public License v2.0
124 stars 34 forks source link

Segfault with simple commands #15

Closed kumy closed 4 years ago

kumy commented 5 years ago

go-crond crash randomly with this trace:

# cat crontab 
@every 5s www-data echo HELLO
@every 1s www-data echo HI

# go-crond -v  crontab --no-auto
go-crond: Starting go-crond version 0.6.1
go-crond: Add cron job spec:'@every 5s' usr:www-data cmd:'echo HELLO'
go-crond: Add cron job spec:'@every 1s' usr:www-data cmd:'echo HI'
go-crond: Start runner with 2 jobs
go-crond: exec: spec:'@every 1s' usr:www-data cmd:'echo HI'
go-crond: ok: spec:'@every 1s' usr:www-data cmd:'echo HI' time:1.084355ms
go-crond: exec: spec:'@every 1s' usr:www-data cmd:'echo HI'
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0xe5 pc=0x7eff8c61d4d8]

runtime stack:
runtime.throw(0x60c5cf, 0x2a)
    /usr/local/go/src/runtime/panic.go:596 +0x95
runtime.sigpanic()
    /usr/local/go/src/runtime/signal_unix.go:274 +0x2db

goroutine 20 [syscall, locked to thread]:
runtime.cgocall(0x51e200, 0xc4200f6b00, 0x60c2bd)
    /usr/local/go/src/runtime/cgocall.go:131 +0xe2 fp=0xc4200f6ac0 sp=0xc4200f6a80
os/user._Cfunc_mygetpwnam_r(0x7eff780008c0, 0xc4200ee3f0, 0x7eff780008e0, 0x400, 0xc4200fe030, 0x0)
    os/user/_obj/_cgo_gotypes.go:161 +0x4d fp=0xc4200f6b00 sp=0xc4200f6ac0
os/user.lookupUser.func2.1(0x7eff780008c0, 0xc4200ee3f0, 0x7eff780008e0, 0x400, 0xc4200fe030, 0xc4200f6ba8)
    /usr/local/go/src/os/user/lookup_unix.go:66 +0x17b fp=0xc4200f6b58 sp=0xc4200f6b00
os/user.lookupUser.func2(0x10)
    /usr/local/go/src/os/user/lookup_unix.go:70 +0x51 fp=0xc4200f6b98 sp=0xc4200f6b58
os/user.retryWithBuffer(0xc4200ec3b0, 0xc4200f6cb0, 0xc4200ec3b0, 0xc420014780)
    /usr/local/go/src/os/user/lookup_unix.go:253 +0x2b fp=0xc4200f6c00 sp=0xc4200f6b98
os/user.lookupUser(0xc42000d9aa, 0x8, 0x0, 0x0, 0x0)
    /usr/local/go/src/os/user/lookup_unix.go:71 +0x1ab fp=0xc4200f6ce8 sp=0xc4200f6c00
os/user.Lookup(0xc42000d9aa, 0x8, 0x9, 0xc42000d9aa, 0x8)
    /usr/local/go/src/os/user/lookup.go:15 +0x35 fp=0xc4200f6d20 sp=0xc4200f6ce8
main.(*Runner).AddWithUser.func1(0xc4200f02c0, 0x2)
    /Users/mblaschke/Projects/go-crond/runner.go:61 +0x84 fp=0xc4200f6de0 sp=0xc4200f6d20
main.(*Runner).cmdFunc.func1()
    /Users/mblaschke/Projects/go-crond/runner.go:133 +0x14d fp=0xc4200f6f90 sp=0xc4200f6de0
github.com/robfig/cron.FuncJob.Run(0xc4200a3180)
    /go/src/github.com/robfig/cron/cron.go:92 +0x25 fp=0xc4200f6fa0 sp=0xc4200f6f90
github.com/robfig/cron.(*Cron).runWithRecovery(0xc420016550, 0x8d4ac0, 0xc4200a3180)
    /go/src/github.com/robfig/cron/cron.go:165 +0x57 fp=0xc4200f6fc8 sp=0xc4200f6fa0
runtime.goexit()
    /usr/local/go/src/runtime/asm_amd64.s:2197 +0x1 fp=0xc4200f6fd0 sp=0xc4200f6fc8
created by github.com/robfig/cron.(*Cron).run
    /go/src/github.com/robfig/cron/cron.go:199 +0x69d

goroutine 1 [chan receive]:
main.main()
    /Users/mblaschke/Projects/go-crond/main.go:413 +0x75c

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
    /usr/local/go/src/runtime/asm_amd64.s:2197 +0x1

goroutine 5 [syscall]:
os/signal.signal_recv(0x0)
    /usr/local/go/src/runtime/sigqueue.go:116 +0x104
os/signal.loop()
    /usr/local/go/src/os/signal/signal_unix.go:22 +0x22
created by os/signal.init.1
    /usr/local/go/src/os/signal/signal_unix.go:28 +0x41

goroutine 6 [select, locked to thread]:
runtime.gopark(0x60e498, 0x0, 0x604d46, 0x6, 0x18, 0x2)
    /usr/local/go/src/runtime/proc.go:271 +0x13a
runtime.selectgoImpl(0xc42003af50, 0x0, 0x18)
    /usr/local/go/src/runtime/select.go:423 +0x1364
runtime.selectgo(0xc42003af50)
    /usr/local/go/src/runtime/select.go:238 +0x1c
runtime.ensureSigM.func1()
    /usr/local/go/src/runtime/signal_unix.go:434 +0x2dd
runtime.goexit()
    /usr/local/go/src/runtime/asm_amd64.s:2197 +0x1

goroutine 7 [chan receive]:
main.registerRunnerShutdown.func1(0xc420014840, 0xc42000e088)
    /Users/mblaschke/Projects/go-crond/main.go:424 +0x68
created by main.registerRunnerShutdown
    /Users/mblaschke/Projects/go-crond/main.go:430 +0xf0

goroutine 8 [select]:
github.com/robfig/cron.(*Cron).run(0xc420016550)
    /go/src/github.com/robfig/cron/cron.go:191 +0x3f0
created by github.com/robfig/cron.(*Cron).Start
    /go/src/github.com/robfig/cron/cron.go:144 +0x55

# go-crond -v  crontab --no-auto
go-crond: Starting go-crond version 0.6.1
go-crond: Add cron job spec:'@every 5s' usr:www-data cmd:'echo HELLO'
go-crond: Add cron job spec:'@every 1s' usr:www-data cmd:'echo HI'
go-crond: Start runner with 2 jobs
go-crond: exec: spec:'@every 1s' usr:www-data cmd:'echo HI'
go-crond: ok: spec:'@every 1s' usr:www-data cmd:'echo HI' time:1.066013ms
go-crond: exec: spec:'@every 1s' usr:www-data cmd:'echo HI'
go-crond: ok: spec:'@every 1s' usr:www-data cmd:'echo HI' time:1.015143ms
go-crond: exec: spec:'@every 1s' usr:www-data cmd:'echo HI'
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0xe5 pc=0x7ff4221064d8]

runtime stack:
runtime.throw(0x60c5cf, 0x2a)
    /usr/local/go/src/runtime/panic.go:596 +0x95
runtime.sigpanic()
    /usr/local/go/src/runtime/signal_unix.go:274 +0x2db
[…]
macropin commented 4 years ago

Not a random crash. It is 100% reproducible on execution of the first crontab. I've encountered this with Debian buster with the 0.6.1 statically linked build. Dynamic build seems to work.

macropin commented 4 years ago

The following Dockerfile will reproduce the issue and crash after 15 seconds:

from debian:buster

RUN apt-get update && apt-get -y install wget \
  && wget https://github.com/webdevops/go-crond/releases/download/0.6.1/go-crond-64-linux \
  && chmod +x go-crond-64-linux \
  && echo "@every 15s www-data echo HI" > crontab

CMD ["/go-crond-64-linux", "root:/crontab"]
linquize commented 4 years ago

Recompile, do not enable CGO. set CGO_ENABLED=0

mblaschke commented 4 years ago

New version coming soon

mblaschke commented 4 years ago

Please try again with 20.6.0, reopen if still exists.

macropin commented 4 years ago

Thanks! The issue is resolved, however it seems that now the metrics http server is always started even when metrics are disabled.

mblaschke commented 4 years ago

Will be fixed with next version.