radiodan / radiodan.js

Radiodan audio server
Other
5 stars 1 forks source link

server attempts to connect to mopidy over telnet before mopidy is running #13

Open tthef opened 9 years ago

tthef commented 9 years ago

When the server starts, I see in the logs that it fails to connect to the mopidy telnet ports because it tries to do so before mopidy is up and running:

debug: [wait-for-socket] Connecting to port 49153
warn: [wait-for-socket] Cannot connect
...
debug: [child-process] INFO Starting Mopidy 1.0.0

I think this might be the root cause of radiodan/meta-radiodan#3

pixelblend commented 9 years ago

The server attempts to connect to the telnet port every few seconds until it succeeds. There was no logging for the success state, which I've added at 7c203bd.

Hopefully this change should help shed some light on the situation.

tthef commented 9 years ago

Updated to 6d0946dd4d0746486bc0290e65df86ead40337dd, and server still does not connect to mopidy; I added a logging into the timeout call back and in the log I see:

Connecting to port 49152
Cannot connect, attempt #1
...
Starting Mopidy 1.0.0
...
Reconnection attempt after failure #1
...
MPD server running at [::ffff:127.0.0.1]:49152]

So, the initial connection fails and the first reconnect timeout triggers still before the MPD server is up, and no further errors or attempts are made.

I think on failure the socket object becomes invalid -- I did a quick test changing the timeout handler to recreate the socket, and this makes the connection and (the playback) work:

setTimeout(function () {
  socket =  new net.Socket();
  addHandlers();
  socket.connect(port);
}, timeout);
pixelblend commented 9 years ago

I've had a quick look at the source code and it looks like reconnecting an old socket should be as good as creating a new one. I've added a fix @8365803 to actively close all activity on the socket before attempting to reconnect.

tthef commented 9 years ago

This does not work. I have even tried to call addHandlers() after the socket.destroy() and that also does not work. The only thing that seems to work is to recreate the socket.