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

ws_client.py uses select.poll without checking module existence #1686

Closed
seanpang-vmware opened this issue Jan 26, 2022 · 6 comments · Fixed by #1848
Closed

ws_client.py uses select.poll without checking module existence #1686

seanpang-vmware opened this issue Jan 26, 2022 · 6 comments · Fixed by #1848
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@seanpang-vmware
Copy link

seanpang-vmware commented Jan 26, 2022

What happened (please include outputs or screenshots):
since version:
Kubernetes API Version: v1.21.7

Bug or Regression
Fixed #741, an issue which prevented Kubernetes cluster api-tokens from exec-plugin auth providers from being refreshed after expiry. (#250, @emenendez)
Use select.poll() for exec on linux/darwin to improve scalability of WSClient (#268, @jsun-splunk)

ws_client.py uses select.poll to exec but did not check if this module exist

if process is monkey patched, this will lead to ApiException.

What you expected to happen:
check if select.poll exist, if not use select.select instead.
/usr/local/lib/python3.8/dist-packages/kubernetes/stream/ws_client.py line 182

       if sys.platform.startswith('linux') or sys.platform in ['darwin']:
            poll = select.poll()
            poll.register(self.sock.sock, select.POLLIN)
            r = poll.poll(timeout)
            poll.unregister(self.sock.sock)

How to reproduce it (as minimally and precisely as possible):
A simple way to reproduce

root@192-161-133-176:/opt/vmware/nsx-cli/bin/python/cli# python3
Python 3.8.10 (default, Sep 28 2021, 16:10:42)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

import select
select.poll()
<select.poll object at 0x7f24f52df390> <----- no monkey patch, works fine

from eventlet import monkey_patch
monkey_patch()

select.poll()
Traceback (most recent call last):
File "", line 1, in
AttributeError: module 'select' has no attribute 'poll' <------ monkey patched, attr lost

from eventlet issue page, this is a design intent:
eventlet/eventlet#608 (comment)

Anything else we need to know?:

Environment:

  • Kubernetes version (kubectl version): 1.22
  • OS (e.g., MacOS 10.13.6): Ubuntu 20.04
  • Python version (python --version) 3.8
  • Python client version (pip list | grep kubernetes) 21.7.0
@seanpang-vmware seanpang-vmware added the kind/bug Categorizes issue or PR as related to a bug. label Jan 26, 2022
@roycaihw
Copy link
Member

@seanpang-vmware Thanks for reporting! Is select.poll only existing in linux / darwin platforms? If so, would you like to send a PR?

@seanpang-vmware
Copy link
Author

@seanpang-vmware Thanks for reporting! Is select.poll only existing in linux / darwin platforms? If so, would you like to send a PR?

No, the issue happened because eventlet is monkey patched, beause select.poll is not thread safe, so eventlet will remove this method after monkey patch. so calling this method will cause "No such module" excpetion.

try this:

import select
from eventlet import monkey_patch
monkey_patch()

select.poll()

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 16, 2022
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Jun 15, 2022
Akasurde added a commit to Akasurde/kubernetes-client-python that referenced this issue Jun 30, 2022
When eventlet is monkey patched, select.poll is removed since
it is not thread safe. So check availability of `poll` method
before using it.

Fixes: kubernetes-client#1753
Fixes: kubernetes-client#1686

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
@Akasurde
Copy link
Contributor

/remove-lifecycle rotten

@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Jun 30, 2022
@Akasurde
Copy link
Contributor

/assign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants