Author: ayoung
Date: Wed Nov  3 02:04:08 2010
New Revision: 9209

URL: http://svn.slimdevices.com/jive?rev=9209&view=rev
Log:
Fixed bug 16617: Controller (SqueezePlay) may never reconnect fully to MySB.com 
after connection loss 

Fix incorrect use of self.state (should be oldstate) in setEndpoint(). Not 
actually provoking a bug at present because the only call to setEndpoint() is 
bracketed by disconnect()/connect() calls.

Server may send reconnection advice of reconnect=none under certain error 
conditions. This causes Comet.lua to enter UNCONNECTED state and not attempt a 
retry, but SlimServer.lua will assume that it is CONNECTING state (retrying). 
In order for it to be possible to escape from this situation, in the case that 
whatever provoked the reconnect=none was actually a transient condition, we 
allow a new request to force a reconnection attempt.

When re-enabling subscriptions that were previously active as part of a new 
handshake, also remove them from the set of sent requests that have not yet 
been acknowledged, and that will get resent when the new connection is 
established; otherwise duplicate subscription requests can be sent.

The RE used to match clientId strings in the response channels of subscription 
requests in the queue was insufficient. It needs also to match 'X' as well as 
hexadecimal characters. 

Include /meta/subscribe along with /meta/reconnect in case this reconnect is 
happening after a successful handshake but failed /meta/connect.

Modified:
    7.6/trunk/squeezeplay/src/squeezeplay/share/jive/net/Comet.lua

Modified: 7.6/trunk/squeezeplay/src/squeezeplay/share/jive/net/Comet.lua
URL: 
http://svn.slimdevices.com/jive/7.6/trunk/squeezeplay/src/squeezeplay/share/jive/net/Comet.lua?rev=9209&r1=9208&r2=9209&view=diff
==============================================================================
--- 7.6/trunk/squeezeplay/src/squeezeplay/share/jive/net/Comet.lua (original)
+++ 7.6/trunk/squeezeplay/src/squeezeplay/share/jive/net/Comet.lua Wed Nov  3 
02:04:08 2010
@@ -188,7 +188,7 @@
        self.chttp:setPriority(Task.PRIORITY_HIGH)
        self.rhttp:setPriority(Task.PRIORITY_HIGH)
 
-       if oldState == CONNECTING or self.state == CONNECTED then
+       if oldState == CONNECTING or oldState == CONNECTED then
                -- Reconnect
                _handshake(self)
        end
@@ -476,6 +476,13 @@
        -- Bump reqid for the next request
        self.reqid = id + 1
 
+       -- SlimServer.lua may think that we are reconnecting but actually we 
are not
+       -- because we got reconnect advice of 'none' previously.
+       -- But this request is likely user-initiated so we should try again now.
+       if self.state == UNCONNECTED or self.state == UNCONNECTING then
+               _reconnect(self)
+       end
+
        -- Send immediately unless we're batching queries
        if self.state ~= CONNECTED or self.batch ~= 0 then
                if self.state ~= CONNECTED then
@@ -581,9 +588,17 @@
 
        -- Go through all existing subscriptions and reset the pending flag
        -- so they are re-subscribed to during _connect()
-       for i, v in ipairs( self.subs ) do
-               log:debug("Will re-subscribe to ", v.subscription)
-               v.pending = true
+       for i, sub in ipairs( self.subs ) do
+               log:debug("Will re-subscribe to ", sub.subscription)
+               sub.pending = true
+               
+               -- Also remove them from the set of requests waiting to be sent
+               -- They will get readded later and we do not want duplicates
+               for j, request in ipairs(self.sent_reqs) do
+                       if sub.reqid == request.id then
+                               table.remove( self.sent_reqs, j )
+                       end
+               end
        end
 
        -- Reset clientId
@@ -649,10 +664,10 @@
 
                        log:debug(self, ": _handshake OK, clientId: ", 
self.clientId)
 
-                       -- Rewrite clientId in requests to be reset
+                       -- Rewrite clientId in requests to be resent
                        for i, req in ipairs(self.sent_reqs) do
                                if req.data.response then
-                                       req.data.response = 
string.gsub(req.data.response, "/(%x+)/", "/" .. self.clientId .. "/")
+                                       req.data.response = 
string.gsub(req.data.response, "/([%xX]+)/", "/" .. self.clientId .. "/")
                                end
                        end
 
@@ -715,6 +730,14 @@
                channel        = '/meta/reconnect',
                clientId       = self.clientId,
                connectionType = 'streaming',
+       },
+       
+       -- Need to include the /meta/subscribe here just in case the one from 
the 
+       -- /meta/connect was lost (see _connect()) due to a network problem 
+       {
+               channel      = '/meta/subscribe',
+               clientId     = self.clientId,
+               subscription = '/' .. self.clientId .. '/**',
        } }
 
        _state(self, CONNECTING)
@@ -834,7 +857,7 @@
                return false
        end
 
-       --try both sent and pending,s ince request may have been sent prior to 
knowing server was down
+       --try both sent and pending, since request may have been sent prior to 
knowing server was down
        for i, request in ipairs( self.sent_reqs ) do
                if request.id == requestId then
                        table.remove( self.sent_reqs, i )

_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/jive-checkins

Reply via email to