Skip to content

Watch stream disconnecting - how to watch forever? #728

@richstokes

Description

@richstokes

Hi,

Is there a way to keep the watch stream connected forever? I am getting disconnected after approx. 5-10 minutes with this error:

Traceback (most recent call last):
  File "/Users/rich/Library/Python/3.7/lib/python/site-packages/urllib3/response.py", line 572, in _update_chunk_length
    self.chunk_left = int(line, 16)
ValueError: invalid literal for int() with base 16: b''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/rich/Library/Python/3.7/lib/python/site-packages/urllib3/response.py", line 331, in _error_catcher
    yield
  File "/Users/rich/Library/Python/3.7/lib/python/site-packages/urllib3/response.py", line 637, in read_chunked
    self._update_chunk_length()
  File "/Users/rich/Library/Python/3.7/lib/python/site-packages/urllib3/response.py", line 576, in _update_chunk_length
    raise httplib.IncompleteRead(line)
http.client.IncompleteRead: IncompleteRead(0 bytes read)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "k8s-live.py", line 69, in watchPodEvents
    for event in w.stream(api_instance.list_pod_for_all_namespaces):
  File "/Users/rich/Library/Python/3.7/lib/python/site-packages/kubernetes/watch/watch.py", line 130, in stream
    for line in iter_resp_lines(resp):
  File "/Users/rich/Library/Python/3.7/lib/python/site-packages/kubernetes/watch/watch.py", line 45, in iter_resp_lines
    for seg in resp.read_chunked(decode_content=False):
  File "/Users/rich/Library/Python/3.7/lib/python/site-packages/urllib3/response.py", line 665, in read_chunked
    self._original_response.close()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 130, in __exit__
    self.gen.throw(type, value, traceback)
  File "/Users/rich/Library/Python/3.7/lib/python/site-packages/urllib3/response.py", line 349, in _error_catcher
    raise ProtocolError('Connection broken: %r' % e, e)
urllib3.exceptions.ProtocolError: ('Connection broken: IncompleteRead(0 bytes read)', IncompleteRead(0 bytes read))

The watch function I am using (which works great up until it gets disconnected):

def watchPodEvents(clusterName):
    api_instance = client.CoreV1Api()
    w = watch.Watch()
    for event in w.stream(api_instance.list_pod_for_all_namespaces):
        print("Cluster: %s Event: %s %s %s" % (clusterName, event['type'],event['object'].kind, event['object'].metadata.name))

    return

Metadata

Metadata

Assignees

No one assigned

    Labels

    lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions