jaraco / jaraco/irc

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

Open
#209 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
421
Forks
90
PR merge metrics
No merged PRs in 30d

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.

Contributor guide

No contributing guide indexed for this repository

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.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.