Bug 15633 - cannot switch to SD card content without network
: cannot switch to SD card content without network
Status: VERIFIED FIXED
Product: SB Touch
Classification: Unclassified
Component: TinySC
: unspecified
: PC Windows XP
: P1 normal (vote)
: 7.5.0
Assigned To: Alan Young
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-02-05 14:44 UTC by Ryan
Modified: 2010-03-04 10:16 UTC (History)
8 users (show)

See Also:
Category: Bug


Attachments
More evidence of issues related to incorrect isConnected() status (4.84 KB, text/plain)
2010-02-16 01:03 UTC, Felix Mueller
Details
event id=nil issue when switching between libraries (30.07 KB, text/plain)
2010-02-16 02:38 UTC, Felix Mueller
Details
Proposed patch (2.68 KB, patch)
2010-02-23 04:54 UTC, Alan Young
Details | Diff
Proposed fail-fast patch (3.46 KB, patch)
2010-02-23 08:57 UTC, Alan Young
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ryan 2010-02-05 14:44:04 UTC
If you are connected to Squeezebox server or tiny SC on another device then loose ethernet connection. You cannot switch to tiny SC SD card content on the device. 

It you conneted to tiny SC library on the device before loss of ethernet you can reconnect without any problem.  

USB works fine
Comment 1 Chris Owens 2010-02-05 16:30:50 UTC
Ping Ryan
Comment 2 Chris Owens 2010-02-05 17:01:23 UTC
Ryan, For future reference, although technically wireless networking is also 'ethernet', we typically use 'ethernet' to describe the RJ45 wired network connection.
Comment 3 Michael Herger 2010-02-07 23:42:17 UTC
Whether you're using USB or SD card shouldn't make any difference at all: they're just different media mounted under TinySBS' music folder.

Did you plug in the SD card while USB was plugged in at the same time? This is currently not supported. Either or, first wins. Is this what you're seeing?
Comment 4 Michael Herger 2010-02-08 04:51:26 UTC
Felix - haven't you been working on some bug re. playback without network?
Comment 5 Felix Mueller 2010-02-08 05:08:45 UTC
If I recall correctly the two scenarios we discussed regarding listening to TinySC without network were:

- What Ryan describes in paragraph two (i.e. listening to TinySC and then network goes away).
- Setup and listening to TinySC without network at all
Comment 6 Michael Herger 2010-02-08 21:23:39 UTC
Felix - may I ask you to investigate this one? Thanks!
Comment 7 Ryan 2010-02-09 15:22:58 UTC
to clarify Chris's comment I was using a wired connection which I then removed it to see I could then switch to on board Tiny SC content.

steps to reproduce
connected via wired Ethernet SD card installed on the unit
connect and play from  tinySC on another unit.
clear playlist/ stop playback 
disconnect Ethernet
switch library    get connection problem message
select continue without network
select itself for library
it fails to find the library

I retried multiple times without success

Eject the SD card and reinserting it waited for squeezebox server to finish discovering files. 
I was able to select and connect to the library after 4 attempts

last visited in fw8467
Comment 8 Felix Mueller 2010-02-11 02:44:35 UTC
Proposed patch to make SlimProto state (UNCONNECTED, CONNECTING, CONNECTED) more reliable. Right now it can oscillate between CONNECTING and CONNECTED even though it isn't connected at all. Alan rightfully urges that all isConnected() calls need to be checked.
Comment 9 Felix Mueller 2010-02-11 02:44:43 UTC
Index: SlimProto.lua
===================================================================
--- SlimProto.lua	(revision 8467)
+++ SlimProto.lua	(working copy)
@@ -542,6 +542,8 @@
 			end
 		end
 
+		self.state = CONNECTED
+
 		-- send acknowledgement
 		if not statusSent then
 			self:sendStatus(opcode)
@@ -595,7 +597,6 @@
 
 	-- connect
 	self.socket:t_connect()
-	self.state = CONNECTED
 	self.txqueue = {}
 
 	-- SC and SN ping the player every 5 and 30 seconds respectively.
@@ -610,7 +611,7 @@
 		(status.isStreaming or status.isLooping)
 
 	-- send helo packet
-	self:send(self.heloPacket)
+	self:send(self.heloPacket, true)
 end
 
 
@@ -700,8 +701,8 @@
 
 -- Sent packet. Returns false is the connection is disconnected and the
 -- packet can't be sent, otherwise it returns true.
-function send(self, packet)
-	if self.state ~= CONNECTED then
+function send(self, packet, force)
+	if not force and self.state ~= CONNECTED then
 		return false
 	end
Comment 10 Felix Mueller 2010-02-16 01:03:12 UTC
Created attachment 6527 [details]
More evidence of issues related to incorrect isConnected() status

IsConnected() is used in various places but if the status is wrong (i.e. CONNECTED) but in reality there is no connection (ethernet cable removed) subsequent code fails miserably.
Comment 11 Felix Mueller 2010-02-16 01:13:02 UTC
Even with my proposed patch (comment #9) there still is an issue right after the connection (SlimProto) goes away.

SlimProto uses two timeouts, a read timeout (10 seconds) and a write timeout (35 seconds). That means if after the network goes down and the next packet is trying to send (write) something it takes 35 seconds before the problem is detected and the connection status changes from CONNECTED to CONNECTING.

If during that timeout time any part of our code tries use this (actually dead) connection an relies on isConnected() it is most likely doing the wrong thing.
Comment 12 Felix Mueller 2010-02-16 02:38:22 UTC
Created attachment 6529 [details]
event id=nil issue when switching between libraries 

Some event id=nil Comet issues I do not understand at all.

Note: I did not even disconnect the network in this case. I only switched between libraries (BigSC, TinySC and mysb.com).

Highlights from the log regarding datestatus subscription:

- 11:16:35 - subscribe to mysb.com (I think) with a valid event id = 21
- 11:16:35 - unsubscribed from Touch, event id = 15
- 11:16:35 - subscribe to mysb.com, event id = 21
- 11:16:37 - response from mysb.com failed due to invalid event id

I fail to understand why the datestatus event id could be invalid in this case.

7.5.0 r8504
Comment 13 Felix Mueller 2010-02-17 01:27:56 UTC
Comment on attachment 6529 [details]
event id=nil issue when switching between libraries 

Opened a new bug 15724 dealing with switching between music libraries (but not related to network going away).
Comment 14 Felix Mueller 2010-02-17 01:29:23 UTC
This bug should only be about isConnected() not being accurate.
Comment 15 Felix Mueller 2010-02-17 08:04:27 UTC
Index: jive/slim/LocalPlayer.lua
===================================================================
--- jive/slim/LocalPlayer.lua	(revision 8506)
+++ jive/slim/LocalPlayer.lua	(working copy)
@@ -14,6 +14,7 @@
 
 local SlimProto      = require("jive.net.SlimProto")
 local Playback       = require("jive.audio.Playback")
+local Timer          = require("jive.ui.Timer")
 
 local jiveMain       = jiveMain
 local debug          = require("jive.utils.debug")
@@ -201,17 +202,46 @@
 
 		server:addLocallyRequestedServer(server)
 		self.slimproto:connect(server)
-	else
+	end
+
+
+	if self:isConnected() then
+		-- First try switching via current server
 		log:info('connectToServer(): switching localPlayer to server', server)
 		local ip, port = server:getIpPort()
 
 		server:addLocallyRequestedServer(server)
-		self:send({'connect', ip}, true)
+
+		-- If switch not successful - try connecting after 5 seconds
+		self.checkConnectTimer = Timer( 5000,
+			function()
+				log:info('connectToServer(): connecting localPlayer to server', server, ' via slimproto')
+
+				-- close any previous connection
+				self.slimproto:disconnect()
+
+				server:addLocallyRequestedServer(server)
+				self.slimproto:connect(server)
+			end,
+			true -- only once
+		)
+		self.checkConnectTimer:start()
+
+		self:call({'connect', ip}, true)
 	end
 	return true
 
 end
 
+
+function _process_connect(self, event)
+	-- Stop connect timer if switch was successful
+	if self.checkConnectTimer and self.checkConnectTimer:isRunning() then
+		self.checkConnectTimer:stop()
+	end
+end
+
+
 function connectIp(self, serverip, slimserverip)
 	self.slimproto:disconnect()
 	self.slimproto:connectIp(serverip, slimserverip)
Comment 16 Felix Mueller 2010-02-17 08:05:30 UTC
Comment #15 contains an untested patch to try to connect to new server after 5 seconds if switching to new server fails due to current server not available anymore.
Comment 17 Chris Owens 2010-02-17 11:31:03 UTC
Felix, Ryan tells me this is now largely working.  What work is left to mark this as 'fixed?'
Comment 18 Chris Owens 2010-02-18 10:15:57 UTC
Alan to review the fix.
Comment 19 Alan Young 2010-02-23 04:54:36 UTC
Created attachment 6556 [details]
Proposed patch

Only have SlimProto:isConnecting() return true when properly connected, and have LocalPlayer use a more robust test to determine if server switching can be accomplished by the currently-connected server.
Comment 20 SVN Bot 2010-02-23 08:00:37 UTC
 == Auto-comment from SVN commit #8556 to the  repo by ayoung ==
 == https://svn.slimdevices.com/?view=revision&revision=8556 ==

bug 15633: cannot switch to SD card content without network 
Only have SlimProto:isConnecting() return true when properly connected, and
have LocalPlayer use a more robust test to determine if server switching can be
accomplished by the currently-connected server.
Comment 21 Alan Young 2010-02-23 08:57:44 UTC
Created attachment 6557 [details]
Proposed fail-fast patch

Felix, Ben, What do you think about this patch to make connection-failure for local players be notified more quickly, rather than having to time out?
Comment 22 Alan Young 2010-02-23 22:54:39 UTC
Update hours
Comment 23 Felix Mueller 2010-02-24 00:08:45 UTC
Alan - I am not sure about the very last change from self:connect() to self:_connectToAddr(). Isn't going through self:connect() meant to pickup server IP address changes in case the server, the player is connected to, goes away and later when it comes back and has a different IP address that would get noted in self.lastServerip?
Comment 24 Alan Young 2010-02-24 02:25:55 UTC
I made the change so that the reset of "self.connectionFailed = false" that now occurs in connect() and connectIp() would not happen when retrying a connection after a failure. In the case that connect() is called with no arguments, as was the case from the retry-timer callback, effectively all it did was;

	local serverip = self.serverip
	_connectToAddr(self, serverip)
	
My change has the timer callback do:

	self:_connectToAddr(self.serverip)

instead of:

	self:connect()
	
I think these should be equivalent.
Comment 25 Felix Mueller 2010-02-24 02:31:54 UTC
You are certainly correct about this. I mistakenly assumed 'server' would be defined from the self: part, but that is clearly not the case. So, yes, I think your change to use _connectToAddr() instead of connect() should be fine.
Comment 26 SVN Bot 2010-02-24 02:36:31 UTC
 == Auto-comment from SVN commit #8561 to the  repo by ayoung ==
 == https://svn.slimdevices.com/?view=revision&revision=8561 ==

bug 15633: cannot switch to SD card content without network 
Make connection-failure for local players be notified more quickly - as
soon as it is detected - rather than having to time out after 20s.
Comment 27 Ryan 2010-02-24 17:03:19 UTC
As FW 8563 this is NOT! working every time.

It takes two tries of inserting the SD card before it is fully recognized.

Steps to reproduce

Power up unit connected with wired Ethernet12, Connect to Squeeze box server, Play some music.

Disconnect Ethernet, Insert SD card, check squeezebox server status, wait for file discovery complete, continue without network, and switch library to TinySC local SD card, 
Indicated library changes from local Squeezebox server to TinySC  SD card. 
Select my music, attempt various combination's of try again and switch library to gain access to music content on the SD card without success.

Go to home menu, eject the SD card, 
Reinsert the SD card, Check Squeezebox server status, wait for files discovery to complete.

Select my music, browse and select music and play. SUCCESS! 

The first attempt installing the SD card gets the library to change and once changed the second try inserting the SD card lets you access it.
Comment 28 Alan Young 2010-02-25 06:15:14 UTC
Actually I think that it is inconsistent. Sometimes it works, sometimes not.
Comment 29 Chris Owens 2010-02-25 09:50:11 UTC
*** Bug 15724 has been marked as a duplicate of this bug. ***
Comment 30 Chris Owens 2010-02-25 10:08:10 UTC
*** Bug 15775 has been marked as a duplicate of this bug. ***
Comment 31 Vahid Fereydouny 2010-02-25 18:21:18 UTC
*** Bug 15627 has been marked as a duplicate of this bug. ***
Comment 32 SVN Bot 2010-02-26 02:50:10 UTC
 == Auto-comment from SVN commit #8583 to the jive repo by ayoung ==
 == https://svn.slimdevices.com/jive?view=revision&revision=8583 ==

Fixed bug 15633: cannot switch to SD card content without network 
SlimMenusApplet: if the server has just connected and we do not have our menus 
yet then the request must have been lost in a transient connection interruption,
so reissue the request for our menus.
The fact that we get a transient connection loss if probably another bug but we
still need to be able to handle the resulting state.

In the case that we get such a transient connection loss then we will end up in the Home 
menu instead of the My Music menu after changing music source.
Comment 33 Alan Young 2010-02-26 04:42:33 UTC
update hours
Comment 34 Ryan 2010-03-04 10:16:25 UTC
fw 8627   I was able to insert and connect to the SD card the first time after loss of network (cable to touch unplugged), and also after loss of local Squeezecenter (turned off). There were a couple times where a message was displayed "problem connecting to library" for the previously selected library. After passing the message I was able to select the SD card as the library and play music. So it is working but not yet elegant.