Replies: 2 comments 4 replies
-
The problem is indeed the regular connection timeout. If you suspend your computer, all the time has passed is counted for the timeout - indeed, MPD hasn't received any input for that amount of time! That's how MPD's timeout works. The easierst way to avoid this problem is to not poll manually, but instead listen for idle events, and only query MPD if something has really changed. Side effect: this reduces CPU wakeups to a minimum and thus saves CPU time and electricity. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've written a small status program that displays the currently loaded song in MPD in my i3 status bar. The code can be found here.
The program uses libmpdclient and basically works like this:
So it connects to MPD over a UNIX domain socket once on startup and than requests the status and current song every 5 seconds reusing the same connection that was initially setup.
My problem is that at some point the connection to MPD breaks causing the process to receive a SIGPIPE. Reading the manpages, this signal occurs when my program tries to write to the UNIX domain socket (for example requesting the current song progress), but there is no one on the other side reading from the socket. This is a bit surprising to me since at no point MPD is stopped or restarted, so why would it stop reading from the socket? If I restart my program, it can communicate again with MPD (for some time until the problem appears again).
I'm not too familiar with how UNIX domain sockets work under the hood.
To investigate this issue, I enabled logging. Here you can see an instance of my program receiving a SIGPIPE:
This is with
log_level "verbose"
. What happened here is that I put my computer into hibernation (as I always do) and then upon resume my client received SIGPIPE (MPD logs a timeout here). The thing is, this does not happen on every resume from hibernate, only occasionally for some reason.Is it expected that an MPD client might receive a SIGPIPE when connecting to MPD using a UNIX domain socket even while MPD is continuously running without getting stopped or restarted? If so, what would be a good strategy to implement here to deal with this situation? Connect once to MPD on startup and then keep checking after each command sent to MPD if we received a SIGPIPE and than reconnect, or just bluntly reconnect to MPD every time we have to run the status commands and then close the connection again every 5 seconds?
This is on Arch Linux, mpd 0.23.12-3 (though this has been an issue for many years), and MPD is started from the systemd-user service that comes with the package.
Beta Was this translation helpful? Give feedback.
All reactions