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 preemption panic #11346

Merged
merged 2 commits into from
Oct 20, 2021
Merged

Fix preemption panic #11346

merged 2 commits into from
Oct 20, 2021

Conversation

notnoop
Copy link
Contributor

@notnoop notnoop commented Oct 19, 2021

Fix a bug where the scheduler may panic when preemption is enabled. The conditions are a bit complicated:
A job with higher priority that schedule multiple allocations that preempt other multiple allocations on the same node, due to port/network/device assignments.

The cause of the bug is incidental mutation of internal cached data. RankedNode computes and cache proposed allocations in https://github.com/hashicorp/nomad/blob/v1.1.6/scheduler/rank.go#L42-L53 . But scheduler then mutates the list to remove pre-emptable allocs in https://github.com/hashicorp/nomad/blob/v1.1.6/scheduler/rank.go#L293-L294, and RemoveAllocs mutates and sets the tail of cached slice with nils triggering a nil-pointer derefencing case.

I fixed the issue by avoiding the mutation in RemoveAllocs - the micro-optimization there doesn't seem necessary.

I've added a test to reproduce the case - it's failing initially in https://app.circleci.com/pipelines/github/hashicorp/nomad/17929/workflows/e2a3a813-351b-40d6-ab78-651de9cf5cae/jobs/178654 .

Fixes #11342

@notnoop notnoop added this to the 1.2.0 milestone Oct 19, 2021
@notnoop notnoop self-assigned this Oct 19, 2021
Copy link
Member

@schmichael schmichael left a comment

Choose a reason for hiding this comment

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

Great work!

@notnoop notnoop merged commit 6d35e2f into main Oct 20, 2021
@notnoop notnoop deleted the b-preemption-panic2 branch October 20, 2021 00:22
notnoop pushed a commit that referenced this pull request Oct 20, 2021
notnoop pushed a commit that referenced this pull request Oct 21, 2021
lgfa29 pushed a commit that referenced this pull request Nov 15, 2021
Fix a bug where the scheduler may panic when preemption is enabled. The conditions are a bit complicated:
A job with higher priority that schedule multiple allocations that preempt other multiple allocations on the same node, due to port/network/device assignments.

The cause of the bug is incidental mutation of internal cached data. `RankedNode` computes and cache proposed allocations  in https://github.com/hashicorp/nomad/blob/v1.1.6/scheduler/rank.go#L42-L53 . But scheduler then mutates the list to remove pre-emptable allocs in https://github.com/hashicorp/nomad/blob/v1.1.6/scheduler/rank.go#L293-L294, and  `RemoveAllocs` mutates and sets the tail of cached slice with `nil`s triggering a nil-pointer derefencing case.

I fixed the issue by avoiding the mutation in `RemoveAllocs` - the micro-optimization there doesn't seem necessary.

Fixes #11342
lgfa29 pushed a commit that referenced this pull request Nov 15, 2021
lgfa29 pushed a commit that referenced this pull request Nov 15, 2021
Fix a bug where the scheduler may panic when preemption is enabled. The conditions are a bit complicated:
A job with higher priority that schedule multiple allocations that preempt other multiple allocations on the same node, due to port/network/device assignments.

The cause of the bug is incidental mutation of internal cached data. `RankedNode` computes and cache proposed allocations  in https://github.com/hashicorp/nomad/blob/v1.1.6/scheduler/rank.go#L42-L53 . But scheduler then mutates the list to remove pre-emptable allocs in https://github.com/hashicorp/nomad/blob/v1.1.6/scheduler/rank.go#L293-L294, and  `RemoveAllocs` mutates and sets the tail of cached slice with `nil`s triggering a nil-pointer derefencing case.

I fixed the issue by avoiding the mutation in `RemoveAllocs` - the micro-optimization there doesn't seem necessary.

Fixes #11342
lgfa29 pushed a commit that referenced this pull request Nov 15, 2021
@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 Nov 10, 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

Successfully merging this pull request may close these issues.

Nomad segfaults when trying to preempt a docker-based job with lower priority
3 participants