shizmob / pydle

An IRCv3-compliant Python 3 IRC library.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Graceless disconnect fails

theunkn0wn1 opened this issue · comments

If the client is unexpectedly disconnected from the server, an unhandled exception occurs.

The stacktrace:

Unexpected disconnect. Attempting to reconnect.
Exception in callback 0(<coroutine ob...002D6C77ACE48>)
handle: <Handle 0(<coroutine ob...002D6C77ACE48>)>
Traceback (most recent call last):
  File "I:\Program Files\python_3_7_1\Lib\asyncio\events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
TypeError: 'int' object is not callable

The setup

Small modifications to the basic echobot example in the readme,

class MyOwnBot(pydle.Client):
    async def on_connect(self):
        await self.join('#unkn0wndev')

    async def on_message(self, source, target, message):
        print(f"[{source}] <{target}>: {message}")

        if message == "qqq":
            print('quitting (gracefully).')
            self.disconnect(expected=True)

        elif message == "QQQ":
            print('quitting (graceless).')
            self.disconnect(expected=False)

Basically, if the message contains QQQ Pydle's disconnect method is invoked, passing expected=False to simulate an unexpected disconnection from IRC.

This invokes Pydle's reconnection logic, which appears to have a few bugs in it. Found while attempting to reproduce #77

I have a few ideas as to why this may be occurring, will investigate.