Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set_keepalive resulting into "irc.client.ServerNotConnectedError: Not connected." #209

Open
OrpheusGr opened this issue Jun 19, 2023 · 0 comments

Comments

@OrpheusGr
Copy link

OrpheusGr commented Jun 19, 2023

I'm developing a Relay Bot for Discord + IRC. It's logic is it creates a new ServerConnection object for each Discord user.
It all works fine, untill i recently made every new connection use the set_keepalive() function.
When i call quit() on a ServerConnection object sortly after i get this error.

File "/home/orfeasgr/NewRelayTest/classcon.py", line 48, in startloop
    reactor.process_once(0.2)
  File "/home/orfeasgr/.local/lib/python3.7/site-packages/irc/client.py", line 830, in process_once
    self.process_timeout()
  File "/home/orfeasgr/.local/lib/python3.7/site-packages/irc/client.py", line 800, in process_timeout
    self.scheduler.run_pending()
  File "/home/orfeasgr/.local/lib/python3.7/site-packages/tempora/schedule.py", line 185, in run_pending
    self.run(command)
  File "/home/orfeasgr/.local/lib/python3.7/site-packages/tempora/schedule.py", line 203, in run
    command.target()
  File "/home/orfeasgr/.local/lib/python3.7/site-packages/irc/client.py", line 556, in ping
    self.send_items('PING', target, target2)
  File "/home/orfeasgr/.local/lib/python3.7/site-packages/irc/client.py", line 595, in send_items
    self.send_raw(' '.join(filter(None, items)))
  File "/home/orfeasgr/.local/lib/python3.7/site-packages/irc/client.py", line 603, in send_raw
    raise ServerNotConnectedError("Not connected.")
irc.client.ServerNotConnectedError: Not connected.

At first i thought it was me using quit() instead of disconnect() but changing that still raised the same error.
Then i wondered if process.once() could be causing the error, but then i realised that would have happened a lot earlier, so i tried to remove the set_keepalive call, which was a much more recent addition to my code and after disconnecting a connection the error didn't happen.

So i came to the conclusion that set_keepalive is apparently called when process_once() is called(?) and that it tries to send a PING command to the server for all ServerConnection objects and that in turn raises the Not Connected error, when any of the objects are not connected.

I assume somewhere along the way the connection object is not removed properly from the Reactor object's connections list when a ServerConnection object is disconnected.

EDIT: I realised i didn't really explain how i'm using the library. My code basically creates a Reactor object and then, when needed, makes a new ServerConnection object, and when needed can disconnect one of those. That's when set_keepalive() ultimately leaded to the error being raised.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant