Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid periodic job cron syntax causes crash loop #4223

Closed
sevagh opened this issue Apr 26, 2018 · 1 comment
Closed

Invalid periodic job cron syntax causes crash loop #4223

sevagh opened this issue Apr 26, 2018 · 1 comment

Comments

@sevagh
Copy link
Contributor

sevagh commented Apr 26, 2018

Nomad version

Nomad v0.7.1 (0b295d399d00199cfab4621566babd25987ba06e)

Operating system and Environment details

Nomad cluster running across a handful of Linux hosts (kernel 3.6, Debian 8).

Issue

When a periodic job with invalid syntax is submitted, e.g.:

"Spec": "1  15-0  *  *  1-5",
"SpecType": "cron"

The underlying cron library (gorhill/cronexpr#35) throws an Index out of range panic. It's the expected behavior by the library (and confirmed by the maintainer), 15-0 is incorrect cron syntax and the library doesn't guarantee behavior for invalid syntax.

However, this makes Nomad get the panic when trying to schedule the job, and they all went into a crash loop:

func (p *PeriodicConfig) Next(fromTime time.Time) time.Time {
	switch p.SpecType {
	case PeriodicSpecCron:
		if e, err := cronexpr.Parse(p.Spec); err == nil {
			return e.Next(fromTime)
		}

https://github.com/hashicorp/nomad/blob/master/nomad/structs/structs.go#L2660

Not sure what the steps are going forward - if there's Nomad-side validation of cron syntax, then why rely on a third-party cron library? Is panic-catching considered idiomatic Go?

Reproduction steps

Pass a periodic job with invalid cron syntax.

Nomad Server logs (if appropriate)

Apr 26 09:28:53 baratheon nomad[612]: panic: runtime error: index out of range
Apr 26 09:28:53 baratheon nomad[612]: goroutine 495 [running]:
Apr 26 09:28:53 baratheon nomad[612]: github.com/hashicorp/nomad/vendor/github.com/gorhill/cronexpr.(*Expression).nextDayOfMonth(0xc423e702a0, 0x3268b4de, 0x
ed273f545, 0x0, 0x0, 0x15, 0x5)
Apr 26 09:28:53 baratheon nomad[612]: /opt/gopath/src/github.com/hashicorp/nomad/vendor/github.com/gorhill/cronexpr/cronexpr_next.go:115 +0x254
Apr 26 09:28:53 baratheon nomad[612]: github.com/hashicorp/nomad/vendor/github.com/gorhill/cronexpr.(*Expression).Next(0xc423e702a0, 0x3268b4de, 0xed273f545,
 0x0, 0x0, 0x1f0e780, 0x362ef45e)
Apr 26 09:28:53 baratheon nomad[612]: /opt/gopath/src/github.com/hashicorp/nomad/vendor/github.com/gorhill/cronexpr/cronexpr.go:210 +0x699
Apr 26 09:28:53 baratheon nomad[612]: github.com/hashicorp/nomad/nomad/structs.(*PeriodicConfig).Next(0xc4234800a0, 0x3268b4de, 0xed273f545, 0x0, 0x3268b4de,
 0xed273f545, 0x0)
Apr 26 09:28:53 baratheon nomad[612]: /opt/gopath/src/github.com/hashicorp/nomad/nomad/structs/structs.go:2353 +0x3a8
Apr 26 09:28:53 baratheon nomad[612]: github.com/hashicorp/nomad/nomad.(*PeriodicDispatch).Add(0xc420492780, 0xc423656340, 0x0, 0x0)
Apr 26 09:28:53 baratheon nomad[612]: /opt/gopath/src/github.com/hashicorp/nomad/nomad/periodic.go:224 +0x2c8
Apr 26 09:28:53 baratheon nomad[612]: github.com/hashicorp/nomad/nomad.(*Server).restorePeriodicDispatcher(0xc42018a1e0, 0x1, 0x0)
Apr 26 09:28:53 baratheon nomad[612]: /opt/gopath/src/github.com/hashicorp/nomad/nomad/leader.go:363 +0x1cf
Apr 26 09:28:53 baratheon nomad[612]: github.com/hashicorp/nomad/nomad.(*Server).establishLeadership(0xc42018a1e0, 0xc42256cae0, 0x3, 0xbeb09d71679c157c)
Apr 26 09:28:53 baratheon nomad[612]: /opt/gopath/src/github.com/hashicorp/nomad/nomad/leader.go:204 +0x24d
Apr 26 09:28:53 baratheon nomad[612]: github.com/hashicorp/nomad/nomad.(*Server).leaderLoop(0xc42018a1e0, 0xc42256cae0)
Apr 26 09:28:53 baratheon nomad[612]: /opt/gopath/src/github.com/hashicorp/nomad/nomad/leader.go:105 +0x552
Apr 26 09:28:53 baratheon nomad[612]: github.com/hashicorp/nomad/nomad.(*Server).monitorLeadership.func1(0xc4257d6000, 0xc42018a1e0, 0xc42256cae0)
Apr 26 09:28:53 baratheon nomad[612]: /opt/gopath/src/github.com/hashicorp/nomad/nomad/leader.go:60 +0x5b
Apr 26 09:28:53 baratheon nomad[612]: created by github.com/hashicorp/nomad/nomad.(*Server).monitorLeadership
Apr 26 09:28:53 baratheon nomad[612]: /opt/gopath/src/github.com/hashicorp/nomad/nomad/leader.go:58 +0x1f9
@sevagh sevagh changed the title Invalid periodic job cron syntax causes big problems Invalid periodic job cron syntax causes crash loop Apr 26, 2018
@github-actions
Copy link

I'm going to lock this issue because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant