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

Reconnect watcher if Kubernetes sends an empty response #95

Closed
JacobHenner opened this issue Feb 29, 2020 · 1 comment
Closed

Reconnect watcher if Kubernetes sends an empty response #95

JacobHenner opened this issue Feb 29, 2020 · 1 comment

Comments

@JacobHenner
Copy link
Contributor

In watch.py, next() is set to stop iteration if the k8s server provides an empty response (i.e. when the server timeout expires). I believe this is undesirable.

line = line.decode('utf8')
# Stop the iterator if K8s sends an empty response. This happens when
# eg the supplied timeout has expired.
if line == '':
raise StopAsyncIteration

Instead, the logic should be similar to the logic in the previous except block, which handles asyncio.TimeoutError:

except asyncio.TimeoutError:
if 'timeout_seconds' not in self.func.keywords:
self.resp.close()
self.resp = None
self.func.keywords['resource_version'] = self.resource_version
continue

From the perspective of kubernetes_asyncio, it should not matter if the client or if the server has timed out; the watcher should attempt to reconnect unless the user-specified timeout (timeout_seconds) has elapsed.

I believe this is how the standard Python client handles it:

https://github.com/kubernetes-client/python-base/blob/d30f1e6fd4e2725aae04fa2f4982a4cfec7c682b/watch/watch.py#L141-L157

When iter_resp_lines(resp) returns a value which evaluates to False (e.g. the k8s api returns an empty response), iteration stops. Unless _stop has been set to True, the client will attempt to reconnect.

@tomplus
Copy link
Owner

tomplus commented Jul 31, 2024

It's been solved in the latest version v30.3.0.

@tomplus tomplus closed this as completed Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants