Senophyx / Discord-RPC

An Python wrapper for Discord RPC
https://pypi.org/project/discord-rpc
MIT License
26 stars 9 forks source link

Program hangs sometimes if discord has been in system tray for a long time. #30

Closed DipeshAggarwal closed 1 month ago

DipeshAggarwal commented 3 months ago

I have been facing this issue intermittently and the only common factor I have managed to find is that it happens when Discord is closed (ie, in the system tray) for a long time.

I managed to isolate the problem to this line https://github.com/Senophyx/Discord-RPC/blob/main/discordrpc/presence.py#L160

enc_header += self.socket.read(header_size)

It seems like when Discord is closed for a long time, the socket enters hibernation and doesn't respond to the request and because of that, the program effectively hangs, waiting for a response.

It can be fixed by opening Discord (from the system tray) but that seems very un-intuitive for end user.

Is there a way to trigger a TimeOut event or something to check if the connection is live?

Senophyx commented 3 months ago

It could be, maybe the program will check every time. But is it the same at the end? if the program pauses if it doesn't get a response from discord, in the end, the rpc doesn't appear.

DipeshAggarwal commented 3 months ago

This can cause the entire program to hang, while it is waiting for a response from Discord. If someone is using this as a package, they might randomly experience this behaviour and would not know what is causing it.

But is it the same at the end? I don't know what you mean by this.

A clarification though, I haven't tested if this happens with _send method too because right now, I'm only setting RPC during program launch and then not touching it again.

Senophyx commented 2 months ago

Sorry for taking so long to reply, as I've been very busy lately.

Anyway, I can't really provide a solution because I still can't replicate this error. I've tried waiting for about 10 minutes in the conditions as described. If this error does happen to you, can you give me an estimate of how long Discord should be in system tray mode? I'll try to replicate it again.

Senophyx commented 2 months ago

This is an error that was not detected in previous version 5.0 tests and almost no other users complained about it.