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

Fix for panic when submitting non-existent version for job history CLI command #4577

Merged
merged 2 commits into from
Aug 14, 2018

Conversation

chelseakomlo
Copy link
Contributor

Fixes a panic where running nomad job history -full -version=500 example would result in:

panic: runtime error: invalid memory address or nil pointer dereference                                  
[signal SIGSEGV: segmentation violation code=0x1 addr=0x100 pc=0x15834a5]                                

goroutine 1 [running]:    
github.com/hashicorp/nomad/command.(*JobHistoryCommand).formatJobVersion(0xc420319a20, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0)
        /opt/gopath/src/github.com/hashicorp/nomad/command/job_history.go:252 +0x45                      
github.com/hashicorp/nomad/command.(*JobHistoryCommand).Run(0xc420319a20, 0xc4200c6030, 0x3, 0x3, 0xc4200a9000)
        /opt/gopath/src/github.com/hashicorp/nomad/command/job_history.go:185 +0xc1d                     
github.com/hashicorp/nomad/vendor/github.com/mitchellh/cli.(*CLI).Run(0xc4202f83c0, 0xc4202f83c0, 0xc42026d4e0, 0x10)
        /opt/gopath/src/github.com/hashicorp/nomad/vendor/github.com/mitchellh/cli/cli.go:255 +0x1eb     
main.RunCustom(0xc4200c6010, 0x5, 0x5, 0xc4204d3f68)                                                     
        /opt/gopath/src/github.com/hashicorp/nomad/main.go:127 +0x4b4                                    
main.Run(0xc4200c6010, 0x5, 0x5, 0xc420098058)      
        /opt/gopath/src/github.com/hashicorp/nomad/main.go:72 +0x3f                                      
main.main()               
        /opt/gopath/src/github.com/hashicorp/nomad/main.go:68 +0x63 

Fixes #4542

Copy link
Member

@nickethier nickethier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should be doing a nil check on the job from the caller as well? Seems like a caller error if it's wanting to format a nil job.

I'm ok with this getting merged though.

if job == nil {
return fmt.Errorf("Error printing job history for non-existing job or job version")
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add a test case for this in job_history_test.go?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are not any success case tests for job_history or similar commands such as job_inspect or job_revert- I tried a couple different test setups but wasn't able to get a successful test passing for this. I'm going to merge as is but we can look at what a success test case could look like.

Copy link
Contributor

@preetapan preetapan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice to verify with a unit test, otherwise LGTM

@chelseakomlo chelseakomlo merged commit 49e96e0 into master Aug 14, 2018
@chelseakomlo chelseakomlo deleted the b-panic-job-history branch August 14, 2018 21:34
@Jeff-Hanson
Copy link

I know this is merged already but was wondering if it would have been better to put the nil check on line 173? That is the first place you know job is nil. That would avoid possibly passing a nil job to the Format call on line 175.

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, 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 Feb 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants