Skip to content

Commit

Permalink
Merge pull request #221 from 2franix/fix_220
Browse files Browse the repository at this point in the history
Propagate exception to all pending commands
  • Loading branch information
mergify[bot] authored Nov 26, 2023
2 parents 417d2ec + 36b2d4c commit c75f0ba
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions mpd/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,18 @@ async def __run(self):
# through the result and terminate the connection

except Exception as e:
# Pass exception to any pending task to terminate them. Otherwise they will hang
# indefinitely as we are about to disconnect.
try:
while not self.__command_queue.empty():
pending_result = self.__command_queue.get_nowait()
pending_result._feed_error(e)
except QueueEmpty:
# As per documentation, the queue raises this type of exception when get_nowait()
# is called and the queue is empty. It actually rather block on the get_nowait() call
# but let's leave the except just in case.
pass

# Prevent the destruction of the pending task in the shutdown
# function -- it's just shutting down by itself.
self.__run_task = None
Expand Down

0 comments on commit c75f0ba

Please sign in to comment.