Repository navigation
fix(stream): handle tuple _request_timeout format in stream websocket calls - #2786
Conversation
|
Welcome @YuvrajLamba01! |
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>
5860d9b to
aab793c
Compare
|
Connect timeout leaks onto post-handshake reads/writes (ws_client.py): |
|
Strengthen test_run_forever_tuple_timeout: Currently only asserts isinstance(..., float). Using (1, 10) and asserting 5 < timeout <= 10 (or mocking time.time) would actually verify timeout[1] is used rather than timeout[0]. Add a portforward_call test: Since portforward_call() is also updated to forward _request_timeout, a quick unit test covering it would round out coverage. |
Reset the underlying socket timeout via websocket.settimeout(read_timeout) after websocket.connect() returns. When _request_timeout is a (connect, read) tuple or (connect, None), this prevents the connect timeout from leaking onto post-handshake socket reads/writes in WSClient.update(), write_stdin(), and PortForward._proxy(). Strengthen test_run_forever_tuple_timeout to verify timeout[1] is extracted and add unit test verifying portforward_call forwards _request_timeout. Signed-off-by: Yuvraj Lamba <yuvrajlamba5151@gmail.com>
|
Thanks for the thorough review and catch regarding the socket timeout leak, @yliaog! Addressed all points in commit
|
|
websocket.settimeout(read_timeout) is called unconditionally even when _request_timeout is omitted (None), which would override a caller's global websocket.setdefaulttimeout(...) if they set one. Guarding it with if _request_timeout is not None: (or only when 'timeout' in connect_opt / tuple) would preserve global defaults when _request_timeout isn't passed — minor edge case, up to you whether it's worth another round-trip. |
Signed-off-by: Yuvraj Lamba <yuvrajlamba5151@gmail.com>
|
Good catch, @yliaog — guarded |
kubernetes-client/python#2786 - fix(stream): handle tuple _request_timeout - 3 files, score: 77/100, 2 critical issues kubernetes-client/python#2762 - Regenerate Python clients with shared legacy - 30 files, score: 77/100, 13 critical issues kubernetes-client/python#2698 - Support _request_timeout in dynamic client - 2 files, score: 66/100, clean code BaaRai/ARTEX#494 - fix(server): do not return database errors - 2 files, score: 68/100, 1 security issue torvalds/GuitarPedal#60 - WebMIDI: keep queued BLE writes - 2 files, score: 77/100, clean code
|
thanks for the PR /lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: yliaog, YuvrajLamba01 The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
5fb3ba1
into
kubernetes-client:master
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_timeoutcan 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 inWSClient.run_forever:In addition,
create_websocket()was not forwarding the connect timeout component toWebSocket.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:
WSClient.run_forever, unpackstimeout = timeout[1]iftimeoutis a 2-tuple, avoiding theTypeErrorand correctly bounding execution by the read timeout.create_websocket, forwards_request_timeout[0](or scalar_request_timeout) toconnect_opt['timeout']forWebSocket.connect()._request_timeoutthroughWSClient.__init__,websocket_call, andportforward_call.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?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: