Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Closed
@seanpang-vmware

Description

@seanpang-vmware

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

Metadata

Metadata

Assignees

Labels

kind/bugCategorizes issue or PR as related to a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions