// Reconnect reconnects to AMQP server
170936
func (b *AMQPCeleryBackend) Reconnect() {
	b.connection.Close()
	conn, channel := NewAMQPConnection(b.host)
	b.Channel = channel
	b.connection = conn
}
139497
func (c *ConnectionStore) Disconnect(expectedServerCert []byte) {
	c.lock.Lock()
	defer c.lock.Unlock()

	conn, connected := c.Connections.Lookup(expectedServerCert)
	if !connected {
		return
	}
	conn.Close()
	c.Connections.Remove(expectedServerCert)
}
803693
func (c *Connection) Disconnect() {
	if c == nil {
		return
	}

	if c.vppClient != nil {
		c.disconnectVPP()
	}
}
1205774
func (b *blockServerRemoteClientHandler) ShouldRetryOnConnect(err error) bool {
	_, inputCanceled := err.(libkb.InputCanceledError)
	return !inputCanceled
}
878894
func (c *Client) Disconnect(quiesce uint) {
	if !c.IsConnected() {
		WARN.Println(CLI, "already disconnected")
		return
	}
	DEBUG.Println(CLI, "disconnecting")
	c.setConnected(disconnected)

	dm := packets.NewControlPacket(packets.Disconnect).(*packets.DisconnectPacket)
	dt := newToken(packets.Disconnect)
	c.oboundP <- &PacketAndToken{p: dm, t: dt}

	// wait for work to finish, or quiesce time consumed
	dt.WaitTimeout(time.Duration(quiesce) * time.Millisecond)
	c.disconnect()
}
480520
func (s *Session) Reconnect(optArgs ...CloseOpts) error {
	var err error

	if err = s.Close(optArgs...); err != nil {
		return err
	}

	s.mu.Lock()
	s.cluster, err = NewCluster(s.hosts, s.opts)
	if err != nil {
		s.mu.Unlock()
		return err
	}

	s.closed = false
	s.mu.Unlock()

	return nil
}
766408
func (f *freeClientPool) disconnect(address string) {
	f.lock.Lock()
	defer f.lock.Unlock()

	if f.closed {
		return
	}
	e := f.addressMap[address]
	now := f.clock.Now()
	if !e.connected {
		log.Debug("Client already disconnected", "address", address)
		return
	}

	f.connPool.Remove(e.index)
	f.calcLogUsage(e, now)
	e.connected = false
	f.disconnPool.Push(e, -e.logUsage)
	log.Debug("Client disconnected", "address", address)
}
814545
func (process *TeleportProcess) reconnectToAuthService(role teleport.Role) (*Connector, error) {
	retryTime := defaults.HighResPollingPeriod
	for {
		connector, err := process.connectToAuthService(role)
		if err == nil {
			// if connected and client is present, make sure the connector's
			// client works, by using call that should succeed at all times
			if connector.Client != nil {
				_, err = connector.Client.GetNamespace(defaults.Namespace)
				if err == nil {
					return connector, nil
				}
				process.Debugf("Connected client %v failed to execute test call: %v. Node or proxy credentials are out of sync.", role, err)
				if err := connector.Client.Close(); err != nil {
					process.Debugf("Failed to close the client: %v.", err)
				}
			}
		}
		process.Infof("%v failed attempt connecting to auth server: %v.", role, err)
		// Wait in between attempts, but return if teleport is shutting down
		select {
		case <-time.After(retryTime):
		case <-process.ExitContext().Done():
			process.Infof("%v stopping connection attempts, teleport is shutting down.", role)
			return nil, ErrTeleportExited
		}
	}
}
936552
func (rtm *RTM) Disconnect() error {
	// always push into the kill channel when invoked,
	// this lets the ManagedConnection() function properly clean up.
	// if the buffer is full then just continue on.
	select {
	case rtm.killChannel <- true:
		return nil
	case <-rtm.disconnected:
		return ErrAlreadyDisconnected
	}
}
1093586
func (c *consulClientImpl) reconnectIfConnectionError(conn *consulConnection, err error) (bool, error) {
	if err == nil {
		return false, nil
	} else if isConsulErrNeedingRetry(err) {
		logrus.Errorf("consul connection error: %v, trying to reconnect..", err)
		if clientErr := c.reconnect(conn); clientErr != nil {
			return false, clientErr
		} else {
			return true, nil
		}
	} else {
		return false, err
	}
}
1032443
func (l VirtualDeviceList) Disconnect(device types.BaseVirtualDevice) error {
	return l.connectivity(device, false)
}
978712
func (c *Client) Disconnect() {
	if c.Connected {
		c.Connected = false
		close(c.closeChan)
		c.conn.Close()
	}
}
1295048
func (c *Client) reconnect() {
	DEBUG.Println(CLI, "enter reconnect")
	c.setConnected(reconnecting)
	var rc byte = 1
	var sleep uint = 1
	var err error

	for rc != 0 {
		cm := newConnectMsgFromOptions(&c.options)

		for _, broker := range c.options.Servers {
		CONN:
			DEBUG.Println(CLI, "about to write new connect msg")
			c.conn, err = openConnection(broker, &c.options.TLSConfig, c.options.ConnectTimeout)
			if err == nil {
				DEBUG.Println(CLI, "socket connected to broker")
				switch c.options.ProtocolVersion {
				case 3:
					DEBUG.Println(CLI, "Using MQTT 3.1 protocol")
					cm.ProtocolName = "MQIsdp"
					cm.ProtocolVersion = 3
				default:
					DEBUG.Println(CLI, "Using MQTT 3.1.1 protocol")
					c.options.ProtocolVersion = 4
					cm.ProtocolName = "MQTT"
					cm.ProtocolVersion = 4
				}
				cm.Write(c.conn)

				rc = c.connect()
				if rc != packets.Accepted {
					c.conn.Close()
					c.conn = nil
					//if the protocol version was explicitly set don't do any fallback
					if c.options.protocolVersionExplicit {
						ERROR.Println(CLI, "Connecting to", broker, "CONNACK was not Accepted, but rather", packets.ConnackReturnCodes[rc])
						continue
					}
					if c.options.ProtocolVersion == 4 {
						DEBUG.Println(CLI, "Trying reconnect using MQTT 3.1 protocol")
						c.options.ProtocolVersion = 3
						goto CONN
					}
				}
				break
			} else {
				ERROR.Println(CLI, err.Error())
				WARN.Println(CLI, "failed to connect to broker, trying next")
				rc = packets.ErrNetworkError
			}
		}
		if rc != 0 {
			DEBUG.Println(CLI, "Reconnect failed, sleeping for", sleep, "seconds")
			time.Sleep(time.Duration(sleep) * time.Second)
			if sleep <= uint(c.options.MaxReconnectInterval.Seconds()) {
				sleep *= 2
			}
		}
	}

	c.pingTimer.Reset(c.options.KeepAlive)
	c.stop = make(chan struct{})

	c.workers.Add(1)
	go outgoing(c)
	go alllogic(c)

	c.setConnected(connected)
	DEBUG.Println(CLI, "client is reconnected")
	if c.options.OnConnect != nil {
		go c.options.OnConnect(c)
	}

	if c.options.KeepAlive != 0 {
		c.workers.Add(1)
		go keepalive(c)
	}
	c.workers.Add(1)
	go incoming(c)
}
178387
func (c *MConnection) _recover() {
	if r := recover(); r != nil {
		err := cmn.ErrorWrap(r, "recovered panic in MConnection")
		c.stopForError(err)
	}
}
9511
func (c *Connection) connect() error {
	var err error
	c.AMQPConn, err = amqp.Dial(c.URL)
	if err != nil {
		return Error(err, "Failed to connect to RabbitMQ")
	}
	c.connected = true
	return nil
}
1184517
func (c *Client) Connect() {
	for c.GetState() == DisconnectedState {
		go c.resubscribe()
		c.doConnection()
		time.Sleep(c.policy.Next())
	}

	c.setState(ClosedState)
}
718296
func (kea *KamEvapi) ReconnectIfNeeded() error {
	if kea.Connected() { // No need to reconnect
		return nil
	}
	var err error
	for i := 0; i < kea.reconnects; i++ {
		if err = kea.Connect(); err == nil || kea.Connected() {
			break // No error or unrelated to connection
		}
		time.Sleep(time.Duration(kea.delayFunc()) * time.Second)
	}
	i := 0
	for {
		if kea.reconnects != -1 && i >= kea.reconnects { // Maximum reconnects reached, -1 for infinite reconnects
			break
		}
		if err = kea.Connect(); err == nil || kea.Connected() {
			kea.delayFunc = fib() // Reset the reconnect delay
			break                 // No error or unrelated to connection
		}
		time.Sleep(time.Duration(kea.delayFunc()) * time.Second)
		i++
	}
	if err == nil && !kea.Connected() {
		return errors.New("Not connected to Kamailio")
	}
	return err // nil or last error in the loop
}