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

helper package functions to copy maps/slices encourage unsafe usage #11564

Closed
tgross opened this issue Nov 24, 2021 · 2 comments
Closed

helper package functions to copy maps/slices encourage unsafe usage #11564

tgross opened this issue Nov 24, 2021 · 2 comments

Comments

@tgross
Copy link
Member

tgross commented Nov 24, 2021

The various generic copy helper functions in the helper package return nil if the input is zero-length. This was likely done to save memory by avoiding heap-allocating empty maps and slices (a few pointers each). But this encourages usage where nil maps are being passed around and need to be checked everywhere after a copy, or we can hit a panic. See #11563 (comment) for an example.

The functions have a lot of callers, so one approach we might want to consider here is having the Copy methods in the nomad/structs package use new variants that allocate the empty map.

@tgross tgross added this to Needs Triage in Nomad - Community Issues Triage via automation Nov 24, 2021
tgross added a commit that referenced this issue Nov 24, 2021
In the system scheduler, if a subset of clients are filtered by class,
we hit a code path where the `AllocMetric` has been copied, but the
`Copy` method does not instantiate the various maps. This leads to an
assignment to a nil map. This changeset ensures that the maps are
non-nil before continuing.

The `Copy` method relies on functions in the `helper` package that all
return nil slices or maps when passed zero-length inputs. This
changeset to fix the panic bug intentionally defers updating those
functions because it'll have potential impact on memory usage. See
#11564 for more details.
@tgross tgross moved this from Needs Triage to Needs Roadmapping in Nomad - Community Issues Triage Nov 24, 2021
tgross added a commit that referenced this issue Nov 24, 2021
In the system scheduler, if a subset of clients are filtered by class,
we hit a code path where the `AllocMetric` has been copied, but the
`Copy` method does not instantiate the various maps. This leads to an
assignment to a nil map. This changeset ensures that the maps are
non-nil before continuing.

The `Copy` method relies on functions in the `helper` package that all
return nil slices or maps when passed zero-length inputs. This
changeset to fix the panic bug intentionally defers updating those
functions because it'll have potential impact on memory usage. See
#11564 for more details.
tgross added a commit that referenced this issue Nov 24, 2021
)

In the system scheduler, if a subset of clients are filtered by class,
we hit a code path where the `AllocMetric` has been copied, but the
`Copy` method does not instantiate the various maps. This leads to an
assignment to a nil map. This changeset ensures that the maps are
non-nil before continuing.

The `Copy` method relies on functions in the `helper` package that all
return nil slices or maps when passed zero-length inputs. This
changeset to fix the panic bug intentionally defers updating those
functions because it'll have potential impact on memory usage. See
#11564 for more details.
lgfa29 pushed a commit that referenced this issue Nov 24, 2021
)

In the system scheduler, if a subset of clients are filtered by class,
we hit a code path where the `AllocMetric` has been copied, but the
`Copy` method does not instantiate the various maps. This leads to an
assignment to a nil map. This changeset ensures that the maps are
non-nil before continuing.

The `Copy` method relies on functions in the `helper` package that all
return nil slices or maps when passed zero-length inputs. This
changeset to fix the panic bug intentionally defers updating those
functions because it'll have potential impact on memory usage. See
#11564 for more details.
@schmichael
Copy link
Member

Fixed by #14139

Nomad - Community Issues Triage automation moved this from Needs Roadmapping to Done Aug 18, 2022
@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 Dec 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Development

No branches or pull requests

2 participants