Invalid Chunk Length when processing Changes feed from Cloudant

915 Views Asked by At

I have a strange error when processing a cloudant changes feed. I have setup a continuous feed something like this:

feed = changes(feed='continuous', include_docs=True, since=db_seqno,filter="xyz/changesFilter")
for change in feed:

The feed runs very well most of the time. After a few hours it starts giving this error "Invalid chunk length". Is this some problem with the urllib library?. Should i upgrade it or do something elese.

("Connection broken: InvalidChunkLength(got length b'', 0 bytes read)", InvalidChunkLength(got length b'', 0 bytes read))
Traceback (most recent call last):
  File "/home/ubuntu/anaconda3/lib/python3.9/site-packages/urllib3/response.py", line 700, 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 "/home/ubuntu/anaconda3/lib/python3.9/site-packages/urllib3/response.py", line 441, in _error_catcher
    yield
  File "/home/ubuntu/anaconda3/lib/python3.9/site-packages/urllib3/response.py", line 767, in read_chunked
    self._update_chunk_length()
  File "/home/ubuntu/anaconda3/lib/python3.9/site-packages/urllib3/response.py", line 704, in _update_chunk_length
    raise InvalidChunkLength(self, line)
urllib3.exceptions.InvalidChunkLength: InvalidChunkLength(got length b'', 0 bytes read)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ubuntu/anaconda3/lib/python3.9/site-packages/requests/models.py", line 760, in generate
    for chunk in self.raw.stream(chunk_size, decode_content=True):
  File "/home/ubuntu/anaconda3/lib/python3.9/site-packages/urllib3/response.py", line 575, in stream
    for line in self.read_chunked(amt, decode_content=decode_content):
  File "/home/ubuntu/anaconda3/lib/python3.9/site-packages/urllib3/response.py", line 796, in read_chunked
    self._original_response.close()
  File "/home/ubuntu/anaconda3/lib/python3.9/contextlib.py", line 137, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/home/ubuntu/anaconda3/lib/python3.9/site-packages/urllib3/response.py", line 458, in _error_catcher
    raise ProtocolError("Connection broken: %r" % e, e)
urllib3.exceptions.ProtocolError: ("Connection broken: InvalidChunkLength(got length b'', 0 bytes read)", InvalidChunkLength(got length b'', 0 bytes read))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/deploy/test.py", line 118, in startchangesfeed
    for change in feed:
  File "/home/ubuntu/anaconda3/lib/python3.9/site-packages/cloudant/feed.py", line 147, in __next__
    return self.next()  # pylint: disable=not-callable
  File "/home/ubuntu/anaconda3/lib/python3.9/site-packages/cloudant/feed.py", line 161, in next
    skip, data = self._process_data(next_(self._lines))
  File "/home/ubuntu/anaconda3/lib/python3.9/site-packages/cloudant/_2to3.py", line 87, in next_
    return next(itr)
  File "/home/ubuntu/anaconda3/lib/python3.9/site-packages/requests/models.py", line 804, in iter_lines
    for chunk in self.iter_content(chunk_size=chunk_size, decode_unicode=decode_unicode):
  File "/home/ubuntu/anaconda3/lib/python3.9/site-packages/requests/models.py", line 763, in generate
    raise ChunkedEncodingError(e)
requests.exceptions.ChunkedEncodingError: ("Connection broken: InvalidChunkLength(got length b'', 0 bytes read)", InvalidChunkLength(got length b'', 0 bytes read))
[2022-12-03 04:28:45] ERROR [test.py.startchangesfeed:150] ("Connection broken: InvalidChunkLength(got length b'', 0 bytes read)", InvalidChunkLength(got length b'', 0 bytes read))
Traceback (most recent call last):
  File "/home/ubuntu/anaconda3/lib/python3.9/site-packages/urllib3/response.py", line 700, 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 "/home/ubuntu/anaconda3/lib/python3.9/site-packages/urllib3/response.py", line 441, in _error_catcher
    yield
  File "/home/ubuntu/anaconda3/lib/python3.9/site-packages/urllib3/response.py", line 767, in read_chunked
    self._update_chunk_length()
  File "/home/ubuntu/anaconda3/lib/python3.9/site-packages/urllib3/response.py", line 704, in _update_chunk_length
    raise InvalidChunkLength(self, line)
urllib3.exceptions.InvalidChunkLength: InvalidChunkLength(got length b'', 0 bytes read)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ubuntu/anaconda3/lib/python3.9/site-packages/requests/models.py", line 760, in generate
    for chunk in self.raw.stream(chunk_size, decode_content=True):
  File "/home/ubuntu/anaconda3/lib/python3.9/site-packages/urllib3/response.py", line 575, in stream
    for line in self.read_chunked(amt, decode_content=decode_content):
  File "/home/ubuntu/anaconda3/lib/python3.9/site-packages/urllib3/response.py", line 796, in read_chunked
    self._original_response.close()
  File "/home/ubuntu/anaconda3/lib/python3.9/contextlib.py", line 137, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/home/ubuntu/anaconda3/lib/python3.9/site-packages/urllib3/response.py", line 458, in _error_catcher
    raise ProtocolError("Connection broken: %r" % e, e)
urllib3.exceptions.ProtocolError: ("Connection broken: InvalidChunkLength(got length b'', 0 bytes read)", InvalidChunkLength(got length b'', 0 bytes read))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/deploy/test.py", line 118, in startchangesfeed
    for change in feed:
  File "/home/ubuntu/anaconda3/lib/python3.9/site-packages/cloudant/feed.py", line 147, in __next__
    return self.next()  # pylint: disable=not-callable
  File "/home/ubuntu/anaconda3/lib/python3.9/site-packages/cloudant/feed.py", line 161, in next
    skip, data = self._process_data(next_(self._lines))
  File "/home/ubuntu/anaconda3/lib/python3.9/site-packages/cloudant/_2to3.py", line 87, in next_
    return next(itr)
  File "/home/ubuntu/anaconda3/lib/python3.9/site-packages/requests/models.py", line 804, in iter_lines
    for chunk in self.iter_content(chunk_size=chunk_size, decode_unicode=decode_unicode):
  File "/home/ubuntu/anaconda3/lib/python3.9/site-packages/requests/models.py", line 763, in generate
    raise ChunkedEncodingError(e)
requests.exceptions.ChunkedEncodingError: ("Connection broken: InvalidChunkLength(got length b'', 0 bytes read)", InvalidChunkLength(got length b'', 0 bytes read))
1

There are 1 best solutions below

0
Anon On

Your CPU might be limited as some changes could be waiting for others to finish parsing and thus timeout, try changing the os_process_timeout in your couchdb config file to a higher value.