Skip to content

fix(stream): handle tuple _request_timeout format in stream websocket calls - #2786

Open
YuvrajLamba01 wants to merge 1 commit into
kubernetes-client:masterfrom
YuvrajLamba01:stream-tuple-request-timeout-2292
Open

YuvrajLamba01 wants to merge 1 commit into
kubernetes-client:masterfrom
YuvrajLamba01:stream-tuple-request-timeout-2292

Conversation

@YuvrajLamba01

Copy link
Copy Markdown

What type of PR is this?

/kind bug

What this PR does / why we need it:

According to the API client documentation and kubernetes/client/rest.py:211-246, _request_timeout can be passed either as a single numeric value (total timeout) or as a pair (tuple) of (connection, read) timeouts.

When using kubernetes.stream (e.g. connect_get_namespaced_pod_exec), passing a tuple previously caused a crash in WSClient.run_forever:

Exception when calling CoreV1Api->connect_get_namespaced_pod_exec: (0)
Reason: '<' not supported between instances of 'float' and 'tuple'

In addition, create_websocket() was not forwarding the connect timeout component to WebSocket.connect(), causing websocket handshakes to fall back to the default 30-second socket timeout even if a lower timeout was specified.

This PR addresses both issues:

  1. In WSClient.run_forever, unpacks timeout = timeout[1] if timeout is a 2-tuple, avoiding the TypeError and correctly bounding execution by the read timeout.
  2. In create_websocket, forwards _request_timeout[0] (or scalar _request_timeout) to connect_opt['timeout'] for WebSocket.connect().
  3. Forwards _request_timeout through WSClient.__init__, websocket_call, and portforward_call.
  4. Adds unit tests covering scalar and tuple timeout handling across create_websocket, run_forever, websocket_call, and _websocket_request.

Which issue(s) this PR fixes:

Fixes #2292

Special notes for your reviewer:

cc: @roycaihw @yliaog

Does this PR introduce a user-facing change?

Support (connection, read) timeout tuple format for _request_timeout in stream calls.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@kubernetes-prow kubernetes-prow Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. labels Nov 15, 2026
@kubernetes-prow
kubernetes-prow Bot requested review from roycaihw and yliaog November 15, 2026 13:01
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: YuvrajLamba01
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

@kubernetes-prow kubernetes-prow Bot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Nov 15, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Welcome @YuvrajLamba01!

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. 😃

@kubernetes-prow kubernetes-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 15, 2026
Support (connect, read) tuple format for _request_timeout in
WSClient and create_websocket, matching the urllib3 Timeout contract
used across REST API calls. Unpack read timeout for run_forever
and pass connect timeout to WebSocket.connect().

Signed-off-by: Yuvraj Lamba <yuvrajlamba5151@gmail.com>
@YuvrajLamba01
YuvrajLamba01 force-pushed the stream-tuple-request-timeout-2292 branch from 5860d9b to aab793c Compare November 15, 2026 13:02
@kubernetes-prow kubernetes-prow Bot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Nov 15, 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. kind/bug Categorizes issue or PR as related to a bug. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

Executing command in pod fails when _request_timeout is passed in tuple format

1 participant