Mic92 / python-mpd2

Python library which provides a client interface for the Music Player Daemon.
GNU Lesser General Public License v3.0
352 stars 119 forks source link

InvalidStateError after seek #148

Closed mweinelt closed 3 years ago

mweinelt commented 3 years ago

After seeking in home-assistant this traceback popped up and the mpd connection stopped working.

2020-12-21 17:36:36 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/nix/store/n3ywcx2q7n2pkb3fwlvgma4shmfar3rg-python3.8-python-mpd2-unstable-2020-12-20/lib/python3.8/site-packages/mpd/asyncio.py", line 259, in __run
    result._feed_error(e)
  File "/nix/store/n3ywcx2q7n2pkb3fwlvgma4shmfar3rg-python3.8-python-mpd2-unstable-2020-12-20/lib/python3.8/site-packages/mpd/asyncio.py", line 76, in _feed_error
    raise error
  File "/nix/store/n3ywcx2q7n2pkb3fwlvgma4shmfar3rg-python3.8-python-mpd2-unstable-2020-12-20/lib/python3.8/site-packages/mpd/asyncio.py", line 245, in __run
    await result._feed_from(self)
  File "/nix/store/n3ywcx2q7n2pkb3fwlvgma4shmfar3rg-python3.8-python-mpd2-unstable-2020-12-20/lib/python3.8/site-packages/mpd/asyncio.py", line 83, in _feed_from
    self.set_result(await mpdclient._read_binary())
asyncio.exceptions.InvalidStateError: invalid state
2020-12-21 17:36:38 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [547577629232] Can not send command to disconnected client

Happens on 5db59fb87a9396d479ddb1e74446aa5c50357f31, I cannot seem to reproduce this issue now. I'm in the process of migrating home-assistants integration to he asyncio implementation.

I guess home-assistant should probably just reconnect in that scenario, if possible. Unrelated and fixed.

Mic92 commented 3 years ago

cc @chrysn

chrysn commented 3 years ago

@mweinelt, I can reproduce some of this by starting a command and cancelling the result; this does give me a hang in the rest of the setup as well.

Looking into the details; should be easy to resolve by shielding the right parts inside the library from cancellation (but maybe there's a smoother way).

mweinelt commented 3 years ago

Wow, thanks alot for the quick assists today. The home-assistant community will rejoice. Okay, they probably won't, but I'll be alot happier, when I can close their issues.

chrysn commented 3 years ago

Funny how everything I do with asyncio winds up being used by HA :-)