Skip to content

fix: handle empty error channel in returncode to prevent race condition#2576

Open
kshiteej-mali wants to merge 1 commit into
kubernetes-client:masterfrom
kshiteej-mali:fix/pod-exec-returncode-race-condition
Open

fix: handle empty error channel in returncode to prevent race condition#2576
kshiteej-mali wants to merge 1 commit into
kubernetes-client:masterfrom
kshiteej-mali:fix/pod-exec-returncode-race-condition

Conversation

@kshiteej-mali
Copy link
Copy Markdown

/kind bug

The returncode property reads from the error channel after the WebSocket connection closes. On fast-exiting commands there is a race condition where the error channel message has not been buffered yet and read_channel() returns an empty string. The previous code passed this directly to yaml.safe_load() and accessed err['status'] without a null check, causing it to incorrectly return 0 even when the command failed with a non-zero exit code.

Fixes #2328 ( pod_exec() yields inconsistent results #2328 )

Reproducible by running command=['false'] in a loop 10 times - previously returned inconsistent exit codes (0 or 1 randomly).

Fixed a race condition in WSClient.returncode that caused pod exec commands with non-zero exit codes to intermittently return 0.

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label May 14, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: kshiteej-mali
Once this PR has been reviewed and has the lgtm label, please assign yliaog for approval. For more information see the Code Review Process.

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

Details 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

@k8s-ci-robot k8s-ci-robot added the do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. label May 14, 2026
@k8s-ci-robot k8s-ci-robot requested review from fabianvf and roycaihw May 14, 2026 18:32
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented May 14, 2026

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: kshiteej-mali / name: kshiteej-mali (370de2b)

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label May 14, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Welcome @kshiteej-mali!

It looks like this is your first PR to kubernetes-client/python 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-client/python has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. kind/bug Categorizes issue or PR as related to a bug. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pod_exec() yields inconsistent results

2 participants