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

flightplan: fix various potential nil panics #119

Merged
merged 1 commit into from
Dec 1, 2023

Conversation

ryancragun
Copy link
Collaborator

When testing scenario filters with negations for variants that didn't exist for some scenarios, I ran into a panic in the Matrix implementation due to not checking for nil and handling it appropriately in our exclusions. After fixing it I decided to use the nilaway[0] static analysis tool to verify the entire flightplan package.

The tool itself definitely has a few rough edges, and there were times when it was confused and I had to do things more than once in a function to please it, but overall it found several useful improvements.

It was fairly time consuming so I scoped this to just the flightplan package for now. Eventually it might be nice to enable for the entire program but we'd either need to architect away our use of global variables for the UI, server client, and server, or we'd need them to reintroduce per line //nolint directives[1].

It also has a few show stopper bugs like not being able to handle listening on a nil channel in a select statement.[2] A tool with a promising and useful future but needs more time for us to enforce.

[0] https://github.com/uber-go/nilaway
[1] uber-go/nilaway#126
[2] uber-go/nilaway#143

When testing scenario filters with negations for variants that didn't
exist for some scenarios, I ran into a panic in the Matrix implementation
due to not checking for nil and handling it appropriately in our
exclusions. After fixing it I decided to use the `nilaway`[0] static
analysis tool to verify the entire `flightplan` package.

The tool itself definitely has a few rough edges, and there were times
when it was confused and I had to do things more than once in a function
to please it, but overall it found several useful improvements.

It was fairly time consuming so I scoped this to just the `flightplan`
package for now. Eventually it might be nice to enable for the entire
program but we'd either need to architect away our use of global
variables for the UI, server client, and server, or we'd need them to
reintroduce per line `//nolint` directives[1].

It also has a few show stopper bugs like not being able to handle
listening on a nil channel in a select statement.[2] A tool with a
promising and useful future but needs more time for us to enforce.

[0] https://github.com/uber-go/nilaway
[1] uber-go/nilaway#126
[2] uber-go/nilaway#143

Signed-off-by: Ryan Cragun <me@ryan.ec>
@ryancragun ryancragun added the changelog/bug Fix for something that wasn't working. Will be included in "Bug Fixes" category in release notes. label Nov 30, 2023
@ryancragun ryancragun requested a review from a team as a code owner November 30, 2023 00:24
@@ -115,7 +115,7 @@ func (e Element) Equal(other Element) bool {

// Match determines if Exclude directive matches the given Vector.
func (ex *Exclude) Match(vec *Vector) bool {
if vec == nil {
if ex == nil || vec == nil {
Copy link
Collaborator Author

@ryancragun ryancragun Nov 30, 2023

Choose a reason for hiding this comment

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

This was the bug that led to the entire PR

@ryancragun ryancragun merged commit 628dd46 into main Dec 1, 2023
6 checks passed
@ryancragun ryancragun deleted the ryan/nil-panic-flightplan branch December 1, 2023 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog/bug Fix for something that wasn't working. Will be included in "Bug Fixes" category in release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants