magicalraccoon / tootstream

A command line interface for interacting with Mastodon instances
MIT License
259 stars 32 forks source link

Exception chain unwinding probably due to server error #183

Closed bingen13 closed 5 years ago

bingen13 commented 6 years ago

Hi,

While using the streaming mode (stream home) I got this (sorry about the irregular wrapping):

---begin exception unwind--- Exception in thread Thread-1: Traceback (most recent call last): File "/home/david/.local/lib/python3.5/site-packages/urllib3/response.py", lin e 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 "/home/david/.local/lib/python3.5/site-packages/urllib3/response.py", lin e 331, in _error_catcher yield File "/home/david/.local/lib/python3.5/site-packages/urllib3/response.py", lin e 637, in read_chunked self._update_chunk_length() File "/home/david/.local/lib/python3.5/site-packages/urllib3/response.py", lin e 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 "/home/david/.local/lib/python3.5/site-packages/requests/models.py", line 749, in generate for chunk in self.raw.stream(chunk_size, decode_content=True): File "/home/david/.local/lib/python3.5/site-packages/urllib3/response.py", lin e 461, in stream for line in self.read_chunked(amt, decode_content=decode_content): File "/home/david/.local/lib/python3.5/site-packages/urllib3/response.py", lin e 665, in read_chunked self._original_response.close() File "/usr/lib/python3.5/contextlib.py", line 77, in exit self.gen.throw(type, value, traceback) File "/home/david/.local/lib/python3.5/site-packages/urllib3/response.py", lin e 349, in _error_catcher raise ProtocolError('Connection broken: %r' % e, e) urllib3.exceptions.ProtocolError: ('Connection broken: IncompleteRead(0 bytes re ad)', IncompleteRead(0 bytes read))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/david/.local/lib/python3.5/site-packages/mastodon/streaming.py", l ine 59, in handle_stream for chunk in response.iter_content(chunk_size = 1): File "/home/david/.local/lib/python3.5/site-packages/requests/models.py", line 752, in generate raise ChunkedEncodingError(e) requests.exceptions.ChunkedEncodingError: ('Connection broken: IncompleteRead(0 bytes read)', IncompleteRead(0 bytes read))

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner self.run() File "/usr/lib/python3.5/threading.py", line 862, in run self._target(*self._args, **self._kwargs) File "/home/david/.local/lib/python3.5/site-packages/mastodon/Mastodon.py", li ne 2082, in _threadproc raise e File "/home/david/.local/lib/python3.5/site-packages/mastodon/Mastodon.py", li ne 2079, in _threadproc listener.handle_stream(r) File "/home/david/.local/lib/python3.5/site-packages/mastodon/streaming.py", l ine 84, in handle_stream err File "", line 3, in raise_from mastodon.Mastodon.MastodonNetworkError: Server ceased communication. ---end exception unwind---

Looks like there was a server issue and it caused a chain of uncaught or mishandled exceptions on tootstream. Just reporting in case it's useful.

magicalraccoon commented 6 years ago

Tootstream streaming gets messed up and drops if the connection is interrupted. I don't know if it's possible or feasible to extend a timeout to prevent hiccups.

craigmaloney commented 6 years ago

We might be able to trap the exception so it doesn't crash the program all the way. But that would require also not trapping everything so actual errors get caught and suppressed.

StarlitGhost commented 5 years ago

Mastodon.py got an update to handle this here https://github.com/halcy/Mastodon.py/commit/d0ae9dcd055e3bdc96a5ab817d14cda012516297, you just need to add a parameter to the stream_* calls.

I've been using a branch with this for the past week, for 3 Mastodon instances (it definitely hasn't lasted this long before).

I'll make a PR.

StarlitGhost commented 5 years ago

PR made #192