FichteFoll / discordrp-mpris

Discord Rich Presence through media players providing the mpris2 dbus interface
MIT License
86 stars 19 forks source link

Warning: socket.send() raised exception [asyncio] #36

Open gaussandhisgun opened 3 weeks ago

gaussandhisgun commented 3 weeks ago

So I'm using this from an AUR package on Arch Linux, with ArmCord flatpak and arRPC (but this also happened to me back when i was using the normal discord app from base repos). After some time and probably some resource usage, the script just starts doing... this. изображение I can CTRL-C out of the script (and it floods my terminal with asyncio errors if i do that), launch it again and keep going, but that needs manual intervention. Maybe there should be a way to auto-restart the script if this kind of thing happens? Like, the script does not stop on these exceptions, but it also does not function until a restart.

This is the commit the AUR package is based on.

BnDLett commented 1 week ago

Perhaps there could be a change in the code where the tool closes upon an exception rather than remaining open. :thinking:

Discord-py-interactions does something like that. If a connection error occurs, then the Python program should be terminated. If you wish to keep it running in the event of a terminating exception, then you'll need an external script that will do that for you.

Although, that shouldn't really be the focus. The focus probably should be why this happens. It may be useful if you go to your configuration file (if it exists) and set the debug variable to true. It should look like this:

config.toml

[global]
debug = true

After that, send the error message here.

gaussandhisgun commented 1 week ago

The error message is approximately 40 000 lines of this:

  File "/usr/lib/python3.12/asyncio/streams.py", line 741, in readexactly                                                                                                 
    raise self._exception                                                                                                                                                 
  File "/usr/lib/python3.12/site-packages/discordrp_mpris/__main__.py", line 91, in run                                                                                   
    await self.tick()                                                                                                                                                     
  File "/usr/lib/python3.12/site-packages/discordrp_mpris/__main__.py", line 182, in tick                                                                                 
    op_recv, result = await self.discord.set_activity(activity)                                                                                                           
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                           
  File "/usr/lib/python3.12/site-packages/discord_rpc/async_.py", line 176, in set_activity                                                                               
    return await self.send_recv(data)                                                                                                                                     
           ^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                     
  File "/usr/lib/python3.12/site-packages/discord_rpc/async_.py", line 144, in send_recv                                                                                  
    reply = await self.recv()                                                                                                                                             
            ^^^^^^^^^^^^^^^^^                                                                                                                                             
  File "/usr/lib/python3.12/site-packages/discord_rpc/async_.py", line 163, in recv                                                                                       
    op, length = await self._recv_header()                                                                                                                                
                 ^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                
  File "/usr/lib/python3.12/site-packages/discord_rpc/async_.py", line 105, in _recv_header                                                                               
    header = await self._recv_exactly(8)                                                                                                                                  
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                  
  File "/usr/lib/python3.12/site-packages/discord_rpc/async_.py", line 252, in _recv_exactly                                                                              
    return await self.reader.readexactly(size)                                                                                                                            
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                            

repeating over and over again.

FichteFoll commented 1 week ago

Is there also a specific exception mentioned somewhere?

FichteFoll commented 1 week ago

Just in case this wasn't obvious already, error handling is … not exactly the forte of this project. Partially because I personally didn't run into many but also because even when running into them, I wasn't sure what exactly to do to remedy the situation. Close the connection and try to start over? Close the application with an exit code to signal errors (and make the systemd unit fail)? Provide configuration for retries? Those are all questions I didn't want to answer back in the day and haven't really looked into again since.

I'll see if I can find some time in the coming weeks to overhaul the code since there are quite a few thinks I've learned since 2018.

Related: #11.