qwertyquerty / pypresence

A complete Discord IPC and Rich Presence wrapper library in Python!
https://qwertyquerty.github.io/pypresence/html/index.html
MIT License
652 stars 76 forks source link

Fix windows rpc close & broken ipc pipe detection #236

Closed NikOverflow closed 8 months ago

NikOverflow commented 8 months ago

It includes this pull request too: https://github.com/qwertyquerty/pypresence/pull/234

Under Windows, the socket is not closed and cleaned up properly for some reason. So we have to force it. This pull request fixes the problem completely.

Here is the POC:

import gc
from pypresence import Presence

rpc = Presence(client_id="1193490043612971030")
rpc.connect()
rpc.close()
rpc = None
gc.collect()

And here is the error:

Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001A7FAAEF160>
Traceback (most recent call last):
  File "C:\Users\joria\anaconda3\lib\asyncio\proactor_events.py", line 115, in __del__
    _warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
  File "C:\Users\joria\anaconda3\lib\asyncio\proactor_events.py", line 79, in __repr__
    info.append(f'fd={self._sock.fileno()}')
  File "C:\Users\joria\anaconda3\lib\asyncio\windows_utils.py", line 102, in fileno   
    raise ValueError("I/O operation on closed pipe")
ValueError: I/O operation on closed pipe

This guy helped me a lot: @JorianWoltjer