archseer/ruby-mpd

Correct way of handling timeouts?

Closed this issue · 3 comments

As the README.md states, version 0.3.0 should introduce some kind of 'reconnect mechanism'. As far as is can see, there is no such mechanism. If the server decides to time out the connection of a ruby-mpd client object, #connected? doesn't report the timed out connection as well as #ping and any call that requires a working connection returns true or throws different exceptions as calls to the sockets #gets function return nil. The only way to detect, that the server closed the connection due to a timeout would be to check #eof? on the socket.
At the moment i'm working on an implementation of the #callback_thread that uses a blocking #gets version of the mpd idle command and as a result of my implementation, not even having callbacks enabled prevents the connection from timing out as there are no frequent polling any more. That is why i stumbled about it.
Am i missing something or is this the intended way the ruby-mpd gem should work?

It seems like the socket doesn't raise a Errno::EPIPE exception in case the server closed the connection. I'am unsure if this is due to changes in mpd or changes of the behaviour of rubys socket class. I'm using mpd 0.19.12 and ruby 2.1.1p76.

I have created a pull request #75 which fixes this issue.

Closed via #75