Skip to content

Conversation

@neo502721
Copy link
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

In the killPods function, directly accessing pod from jobInfo.Pods[target.TaskName][target.PodName]
could cause a nil pointer dereference error when target.Type is TargetTypePod. This is because
if target.TaskName does not exist in jobInfo.Pods, or target.PodName does not exist in the
corresponding task, accessing this map would cause a panic.

This fix prevents direct access to potentially non-existent map keys by checking if the task
and pod exist, thereby preventing nil pointer dereference errors.

Which issue(s) this PR fixes:

Fixes #4543

Special notes for your reviewer:

Does this PR introduce a user-facing change?


@volcano-sh-bot
Copy link
Contributor

Welcome @neo502721!

It looks like this is your first PR to volcano-sh/volcano.

Thank you, and welcome to Volcano. 😃

@volcano-sh-bot volcano-sh-bot added the kind/bug Categorizes issue or PR as related to a bug. label Aug 26, 2025
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @neo502721, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical bug in the job controller's killPods action that could lead to a nil pointer dereference. Previously, direct access to jobInfo.Pods using potentially non-existent target.TaskName or target.PodName could cause the application to panic. The fix introduces robust checks to validate the existence of these keys before map access, significantly enhancing the stability and reliability of the job controller's pod termination logic.

Highlights

  • Bug Fix - Nil Pointer Dereference: Addresses a potential nil pointer dereference in the killPods function within the job controller.
  • Robust Map Access: Implements checks for the existence of target.TaskName and target.PodName in the jobInfo.Pods map before attempting to access their values, preventing panics.
  • Improved Error Prevention: Ensures that the podsToKill map is populated safely, even if the target task or pod does not exist in the jobInfo.Pods structure.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@volcano-sh-bot volcano-sh-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Aug 26, 2025
@neo502721
Copy link
Contributor Author

/assign @hzxuzhonghu

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly addresses a potential nil pointer dereference in the killPods function by adding necessary checks before accessing nested maps. The fix is direct and effective. I've included one suggestion to refactor the conditional logic using a switch statement, which could improve readability and maintainability.

Comment on lines 102 to 112
if target.Type == state.TargetTypeTask {
podsToKill = jobInfo.Pods[target.TaskName]
if targetPods, found := jobInfo.Pods[target.TaskName]; found {
podsToKill = targetPods
}
} else if target.Type == state.TargetTypePod {
podsToKill[target.PodName] = jobInfo.Pods[target.TaskName][target.PodName]
if targetPods, found := jobInfo.Pods[target.TaskName]; found {
if pod, found := targetPods[target.PodName]; found {
podsToKill[target.PodName] = pod
}
}
}

Choose a reason for hiding this comment

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

medium

The if-else if structure works, but using a switch statement on target.Type would be more idiomatic Go in this case. It improves readability and makes the code more extensible if more TargetType values are added in the future.

Suggested change
if target.Type == state.TargetTypeTask {
podsToKill = jobInfo.Pods[target.TaskName]
if targetPods, found := jobInfo.Pods[target.TaskName]; found {
podsToKill = targetPods
}
} else if target.Type == state.TargetTypePod {
podsToKill[target.PodName] = jobInfo.Pods[target.TaskName][target.PodName]
if targetPods, found := jobInfo.Pods[target.TaskName]; found {
if pod, found := targetPods[target.PodName]; found {
podsToKill[target.PodName] = pod
}
}
}
switch target.Type {
case state.TargetTypeTask:
if targetPods, found := jobInfo.Pods[target.TaskName]; found {
podsToKill = targetPods
}
case state.TargetTypePod:
if targetPods, found := jobInfo.Pods[target.TaskName]; found {
if pod, found := targetPods[target.PodName]; found {
podsToKill[target.PodName] = pod
}
}
}

@neo502721 neo502721 force-pushed the master branch 2 times, most recently from 866f89d to d0123c5 Compare August 26, 2025 02:09
@hzxuzhonghu
Copy link
Member

/ok-to-test

@volcano-sh-bot volcano-sh-bot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Aug 26, 2025
Copy link
Member

@hzxuzhonghu hzxuzhonghu left a comment

Choose a reason for hiding this comment

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

genrally lg, could you add a test case for it

@neo502721
Copy link
Contributor Author

genrally lg, could you add a test case for it
Okay, I will add it later today.

@xanderdunn
Copy link

Thanks so much for this fix, really appreciate it!

@volcano-sh-bot volcano-sh-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 27, 2025
@volcano-sh-bot volcano-sh-bot added the lgtm Indicates that a PR is ready to be merged. label Aug 27, 2025
@volcano-sh-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hzxuzhonghu

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@volcano-sh-bot volcano-sh-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 27, 2025
@volcano-sh-bot volcano-sh-bot merged commit b27b2a9 into volcano-sh:master Aug 27, 2025
20 checks passed
@kingeasternsun
Copy link
Contributor

/lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

volcano-controllers pod invalid memory address or nil pointer dereference

5 participants