                 internalConnect();
             }
         }
-	}
-
-	/**
-	 *  Disconnects the ChannelSet from the Channel. If the Channel is connected
-	 *  to its endpoint and it has no more connected ChannelSets it will 
-	 *  internally disconnect.
-	 *
-	 *  <p>Channel subclasses need to override the 
-	 *  <code>internalDisconnect()</code> method, and call the
-	 *  <code>disconnectSuccess()</code> method when the underlying connection
-	 *  has been terminated.</p>
-	 * 
-	 *  @param channelSet The ChannelSet to disconnect from the Channel.
-	 */
-	final public function disconnect(channelSet:ChannelSet):void
-	{
-	    // If we own the wait guard for initial Channel connects release it.
-	    // This will only be true if this Channel is the first to attempt to connect
-	    // but its connect attempt is still pending when disconnect() is invoked.
-	    if (_ownsWaitGuard)
-	    {
-	        _ownsWaitGuard = false;
-	        FlexClient.getInstance().waitForFlexClientId = false; // Allow other Channels to connect.
-	    }
-	    
-	    // Disconnect the channelSet.
-	    var i:int = channelSet != null ? _channelSets.indexOf(channelSet) : -1;
+    }
+
+    /**
+     *  Disconnects the ChannelSet from the Channel. If the Channel is connected
+     *  to its endpoint and it has no more connected ChannelSets it will
+     *  internally disconnect.
+     *
+     *  <p>Channel subclasses need to override the
+     *  <code>internalDisconnect()</code> method, and call the
+     *  <code>disconnectSuccess()</code> method when the underlying connection
+     *  has been terminated.</p>
+     *
+     *  @param channelSet The ChannelSet to disconnect from the Channel.
+     */
+    final public function disconnect(channelSet:ChannelSet):void
+    {
+        // If we own the wait guard for initial Channel connects release it.
+        // This will only be true if this Channel is the first to attempt to connect
+        // but its connect attempt is still pending when disconnect() is invoked.
+        if (_ownsWaitGuard)
+        {
+            _ownsWaitGuard = false;
+            FlexClient.getInstance().waitForFlexClientId = false; // Allow other Channels to connect.
+        }
+
+        // Disconnect the channelSet.
+        var i:int = channelSet != null ? _channelSets.indexOf(channelSet) : -1;
         if (i != -1)
         {
             _channelSets.splice(i, 1);
             // Remove the ChannelSet as a listener to this Channel.
             removeEventListener(ChannelEvent.CONNECT, channelSet.channelConnectHandler, false);
-            removeEventListener(ChannelEvent.DISCONNECT, channelSet.channelDisconnectHandler, false);                
+            removeEventListener(ChannelEvent.DISCONNECT, channelSet.channelDisconnectHandler, false);
             removeEventListener(ChannelFaultEvent.FAULT, channelSet.channelFaultHandler, false);
-            
-            // Notify the ChannelSet of the disconnect.                
-            if (connected) 
-            {    
+
+            // Notify the ChannelSet of the disconnect.
+            if (connected)
+            {
                 channelSet.channelDisconnectHandler(ChannelEvent.createEvent(ChannelEvent.DISCONNECT, this, false));
             }
-        
-    	    // Shut down the underlying connection if this Channel has no more 
-    	    // ChannelSets using it.
+
+            // Shut down the underlying connection if this Channel has no more
+            // ChannelSets using it.
             if (_channelSets.length == 0)
             {
                 _shouldBeConnected = false;

                return; // Exit early.
            }
        }
        
        // Potentially continue reliable reconnect loop.
        if (reliableReconnectDuration != -1)
        {
            _reliableReconnectLastTimestamp = new Date().valueOf();
            var remaining:Number = reliableReconnectDuration - (_reliableReconnectLastTimestamp - _reliableReconnectBeginTimestamp);            
            if (remaining > 0)
            {                                
                // Apply exponential backoff.
                var delay:int = 1000; // 1 second.
                delay << ++_reliableReconnectAttempts;
                if (delay < remaining)
                {
                    new AsyncDispatcher(reconnect, null, delay);
                    return; // Exit early. 
                }
            }
            // At this point the reliable reconnect duration has been exhausted.
            reliableReconnectCleanup();
        }
        
        // General failover handling.
        ++_failoverIndex;
        if ((_failoverIndex + 1) <= failoverURIs.length)
        {
	        setReconnecting(true);
            uri = failoverURIs[_failoverIndex];
            
            if (Log.isInfo())
            {
		        _log.info("'{0}' channel attempting to connect to {1}.", id, endpoint);
            }
            // NetConnection based channels may have their underlying resources
            // GC'ed at the end of the execution of the handler that has
            // invoked this method, which means that the results of a call to 
            // internalConnect() for these channels may magically vanish once 
            // the handler exits. 
            // A timer introduces a slight delay in the reconnect attempt to
            // give the handler time to finish executing, at which point the 
            // internals of a NetConnection channel will be stable and we can 
            // attempt to connect successfully.
            // This timer is applied to all channels but the impact is small 
            // enough and the failover scenario rare enough that special casing 
            // this for only NetConnection channels is more trouble than it's 
            // worth. 
            new AsyncDispatcher(reconnect, null, 1);          
        }
        else
        {
            if (Log.isInfo())
            {
		        _log.info("'{0}' channel has exhausted failover options and has reset to its primary endpoint.", id);
		    }
            // Nothing left to failover to; reset to primary.
            resetToPrimaryURI();         
        }
    }
    
    /**
     *  @private
     *  Cleanup following a connect or failover attempt.

        // Potentially enter reliable reconnect loop.
        if (_previouslyConnected)
        {
            _previouslyConnected = false;

            var acs:Class = null;
            try
            {
                acs = getDefinitionByName("mx.messaging.AdvancedChannelSet") as Class;
            }
            catch (ignore:Error) {}
            var duration:int = -1;
            if (acs != null)
            {
                for each (var channelSet:ChannelSet in channelSets)
                {
                    if (channelSet is acs)
