ncTelegram icon indicating copy to clipboard operation
ncTelegram copied to clipboard

Remote end closed

Open Bergiu opened this issue 6 years ago • 11 comments

Sometimes it randomly crashes and this Traceback is shown:

Exception in thread Receiver (pytg):
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 "/usr/local/lib/python3.5/dist-packages/pytg/receiver.py", line 125, in _receiver
    raise ConnectionError("Remote end closed.")
pytg.exceptions.ConnectionError: Remote end closed.

Traceback (most recent call last):
  File "/usr/local/bin/nctelegram", line 93, in <module>
    ncTelegram.Telegram_ui(config_full)
  File "/usr/local/lib/python3.5/dist-packages/ncTelegram/__init__.py", line 91, in __init__
    self.main_loop.run()
  File "/usr/lib/python3/dist-packages/urwid/main_loop.py", line 278, in run
    self._run()
  File "/usr/lib/python3/dist-packages/urwid/main_loop.py", line 376, in _run
    self.event_loop.run()
  File "/usr/lib/python3/dist-packages/urwid/main_loop.py", line 682, in run
    self._loop()
  File "/usr/lib/python3/dist-packages/urwid/main_loop.py", line 719, in _loop
    self._watch_files[fd]()
  File "/usr/lib/python3/dist-packages/urwid/raw_display.py", line 393, in <lambda>
    event_loop, callback, self.get_available_raw_input())
  File "/usr/lib/python3/dist-packages/urwid/raw_display.py", line 493, in parse_input
    callback(processed, processed_codes)
  File "/usr/lib/python3/dist-packages/urwid/main_loop.py", line 403, in _update
    self.process_input(keys)
  File "/usr/lib/python3/dist-packages/urwid/main_loop.py", line 503, in process_input
    k = self._topmost_widget.keypress(self.screen_size, k)
  File "/usr/lib/python3/dist-packages/urwid/container.py", line 2269, in keypress
    key = w.keypress((mc,) + size[1:], key)
  File "/usr/local/lib/python3.5/dist-packages/ncTelegram/ui_chanwidget.py", line 195, in keypress
    key = super(ChanWidget, self).keypress(size, key)
  File "/usr/lib/python3/dist-packages/urwid/listbox.py", line 985, in keypress
    key = focus_widget.keypress((maxcol,),key)
  File "/usr/lib/python3/dist-packages/urwid/wimp.py", line 535, in keypress
    self._emit('click')
  File "/usr/lib/python3/dist-packages/urwid/widget.py", line 463, in _emit
    signals.emit_signal(self, name, self, *args)
  File "/usr/lib/python3/dist-packages/urwid/signals.py", line 264, in emit
    result |= self._call_callback(callback, user_arg, user_args, args)
  File "/usr/lib/python3/dist-packages/urwid/signals.py", line 294, in _call_callback
    return bool(callback(*args_to_pass))
  File "/usr/local/lib/python3.5/dist-packages/ncTelegram/ui_chanwidget.py", line 177, in chan_change
    self.Telegram_ui.msg_widget.get_history()
  File "/usr/local/lib/python3.5/dist-packages/ncTelegram/ui_msgwidget.py", line 60, in get_history
    self.print_msg(msg)
  File "/usr/local/lib/python3.5/dist-packages/ncTelegram/ui_msgwidget.py", line 141, in print_msg
    msg_reply = self.Telegram_ui.sender.message_get(msg['reply_id'])
  File "/usr/local/lib/python3.5/dist-packages/pytg/sender.py", line 630, in command_alias
    return self.execute_function(command_name, *args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/pytg/sender.py", line 320, in execute_function
    result = self._do_send(request, answer_timeout=self.default_answer_timeout, retry_connect=retry_connect)
  File "/usr/local/lib/python3.5/dist-packages/pytg/sender.py", line 507, in _do_send
    raise ConnectionError("Remote end closed")
pytg.exceptions.ConnectionError: Remote end closed

Bergiu avatar Jul 19 '17 13:07 Bergiu

It happens, when there is a reply to a deleted message

Bergiu avatar Jul 19 '17 14:07 Bergiu

Hi, Thanks a lot for reporting this, iirc I already tried to fix it but the issue is that there is no way to check if the message have been deleted or not. And since getting the message makes pytg/telegram-cli crash you can't use exceptions in nctelegram to prevent it because you need to relaunch the entire software after it happens...

If you manage to come up with a solution for that I'll be more than happy to merge, but for now, II have no idea how to fix that.

Nanoseb avatar Jul 19 '17 21:07 Nanoseb

I have made a small fix. Every time ncTelegram crashes with this bug, it saves the message id in the file "forbidden_messages.txt", so the next time ncTelegram wants to load this message, it skips this step.

https://github.com/Bergiu/ncTelegram/tree/bugfix/deleted_msg

Bergiu avatar Jul 19 '17 21:07 Bergiu

Maybe it can be improved, by saving the messages in a database and automatically restart the application.

Bergiu avatar Jul 19 '17 21:07 Bergiu

More importantly, where do you save this file, this can't be in the 'installation' folder because if you have made a proper install of nctelegram you won't have write permissions there. Hence you probably want to save that in ~/.config/nctelegram and then move the configuration file from ~ to that folder.

I am not sure about restarting nctelegram from nctelegram though, it will be weird form an user point of view having the software restart by itself.

Finally, try to be consistent in the naming conventions, functions in ncTelegram don't use camelCase and these are not just 'numbers' but msg_id. Sorry if I am being picky here.

Nanoseb avatar Jul 19 '17 21:07 Nanoseb

yes this was just for testing if it works that way

Bergiu avatar Jul 19 '17 21:07 Bergiu

have the same issue :-1:

darker0n avatar Aug 06 '17 10:08 darker0n

https://github.com/Nanoseb/ncTelegram/issues/8 i think it's this bug too

darker0n avatar Aug 06 '17 10:08 darker0n

yes same bug indeed, I don't have time to dev nctelegram these days, but if someone wants to implement Bergiu's method I'll be happy to merge.

Nanoseb avatar Aug 07 '17 16:08 Nanoseb

Same issue.

sistematico avatar Nov 26 '17 19:11 sistematico

Same issue.

matheusfillipe avatar May 19 '20 03:05 matheusfillipe