shizmob / pydle

An IRCv3-compliant Python 3 IRC library.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BasicClient.quit("Message") does not display custom message on quit event.

shatteredbeam opened this issue · comments

commented

When using .quit("Some Custom Message") the client disconnects cleanly, but it does not display its quit message, only its own nickname which is usually added by the server, indicating the custom message is not being passed by the method to the server.

Am able to reproduce, current theory is there is a race condition during Exit.

What appears to happen is Pydle sends a QUIT message with the correct payload, but then immediately closes its connection with the server.

According to the RFC specification, the server sends an acknowledgement ERROR message in response, which it can't do if pydle closes the link.

Here is a comparison between Pydle (top) and Hexchat(bottom) as seen by Wireshark.
image

To resolve this chicken/egg scenario, We need a way of communicating to pydle.Client.disconnect(expected:bool) that an incoming disconnect is expected, without calling the method itself. In order for the exit message to be properly acknowledged by the IRC server, pydle must remain connected until the server sends back an acknowledgement. Unfortunately this acknowledgement is immediately followed by the server closing the link.

I think a viable approach would be to use an asyncio.Event as a flag, stored in the pydle.Client instance.
When pydle is asked to quit gracefully, it will set this flag and send the quit message to IRC.
When disconnect is inevitably called it can check the state of this flag (as opposed to it being passed as an argument), thus allowing it to treat an incoming disconnect as expected while allowing something else to cause the disconnect.