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

Open
#209 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
python
Domain
networking

Research direction

Read irc/client.py around ServerConnection.set_keepalive(), Reactor.process_once(), the scheduler callback, and send_raw(); reproduce the traceback with multiple connections and then disconnect one. Done means processing the reactor after a connection is disconnected no longer attempts a keepalive that raises ServerNotConnectedError.

Written by the indexing model from the issue text.

Description

I'm developing a Relay Bot for Discord + IRC. Its 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.

Dominant language
Python
Stars
422
Forks
91
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from jaraco/irc

All issues in jaraco/irc

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.