Check connection exceptions.
343095
def check_connection(func):
    """"""
    @wraps(func)
    def with_exception_handling(*args, **kwargs):
        """Wrap function being decorated."""
        try:
            return func(*args, **kwargs)
        except redis.exceptions.ConnectionError:
            raise ConnectionError("Unable to connect to the Redis "
                                  "Configuration Database. host = {}, "
                                  "port = {}, id = {}."
                                  .format(REDIS_HOST, REDIS_PORT,
                                          REDIS_DB_ID))
    return with_exception_handling
678177
private boolean checkConnection() {
		if (connection == null) {
			if (System.currentTimeMillis() >= reconnectTimestamp) {
				long start = System.currentTimeMillis();
				try {
					connection = connect(url, user, password);
					statement = connection.prepareStatement(sql);
					InternalLogger.log(Level.ERROR, "Lost log entries due to broken database connection: " + lostCount);
					lostCount = 0;
					return true;
				} catch (NamingException ex) {
					long now = System.currentTimeMillis();
					reconnectTimestamp = now + Math.max(MIN_RETRY_INTERVAL, (now - start) * 2);
					closeConnectionSilently();
					return false;
				} catch (SQLException ex) {
					long now = System.currentTimeMillis();
					reconnectTimestamp = now + Math.max(MIN_RETRY_INTERVAL, (now - start) * 2);
					closeConnectionSilently();
					return false;
				}
			} else {
				return false;
			}
		} else {
			return true;
		}
	}
532934
private void tryConnecting() {
        LOG.debug("Trying to connect");

        // Get a server with which to try to connect.
        final Optional<T> optionalServerIdToTry = getServerIdToTry();

        // It is possible that we are unable to find a server. In this case,
        // fall back to the last resort server.
        final OptionalVisitor<Void, T> serverToTryVisitor = new OptionalVisitor<Void, T>() {
            public Void visitNone(final None<T> none) {
                LOG.debug("No connections to try...");
                // We could not find a server. Handle this case appropriately.

                // We only need this if we start running a naked server
                // somewhere to support our network. Otherwise, any running
                // servers should be found by the candidate provider.
                // handleNoServerIdToTry ();
                return null;
            }

            public Void visitSome(final Some<T> some) {
                // We found a server. Establish a connection with it.
                LOG.debug("Establishing connection...");
                establish(some.object());
                return null;
            }
        };

        optionalServerIdToTry.accept(serverToTryVisitor);
    }
897429
def _is_connreset(self, exc: BaseException) -> bool:
        
        return (
            isinstance(exc, (socket.error, IOError))
            and errno_from_exception(exc) in _ERRNO_CONNRESET
        )
1132099
def check_connections(self):
        """"""
        switch_connections = self._mdriver.get_all_switch_ips()

        for switch_ip in switch_connections:
            state = self._mdriver.get_switch_ip_and_active_state(switch_ip)
            config_failure = self._mdriver.get_switch_replay_failure(
                const.FAIL_CONFIG, switch_ip)
            contact_failure = self._mdriver.get_switch_replay_failure(
                const.FAIL_CONTACT, switch_ip)
            LOG.debug("check_connections() thread %(thid)d, switch "
                      "%(switch_ip)s state %(state)s "
                      "contact_failure %(contact_failure)d "
                      "config_failure %(config_failure)d ",
                      {'thid': threading.current_thread().ident,
                       'switch_ip': switch_ip, 'state': state,
                       'contact_failure': contact_failure,
                       'config_failure': config_failure})
            try:
                # Send a simple get nexus type to determine if
                # the switch is up
                nexus_type = self._driver.get_nexus_type(switch_ip)
            except Exception:
                if state != const.SWITCH_INACTIVE:
                    LOG.error("Lost connection to switch ip "
                        "%(switch_ip)s", {'switch_ip': switch_ip})
                    self._mdriver.set_switch_ip_and_active_state(
                        switch_ip, const.SWITCH_INACTIVE)
                else:
                    self._mdriver.incr_switch_replay_failure(
                        const.FAIL_CONTACT, switch_ip)
            else:
                if state == const.SWITCH_RESTORE_S2:
                    try:
                        self._mdriver.configure_next_batch_of_vlans(switch_ip)
                    except Exception as e:
                        LOG.error("Unexpected exception while replaying "
                                  "entries for switch %(switch_ip)s, "
                                  "Reason:%(reason)s ",
                                  {'switch_ip': switch_ip, 'reason': e})
                        self._mdriver.register_switch_as_inactive(
                            switch_ip, 'replay next_vlan_batch')
                    continue

                if state == const.SWITCH_INACTIVE:
                    self._configure_nexus_type(switch_ip, nexus_type)
                    LOG.info("Re-established connection to switch "
                        "ip %(switch_ip)s",
                        {'switch_ip': switch_ip})

                    self._mdriver.set_switch_ip_and_active_state(
                        switch_ip, const.SWITCH_RESTORE_S1)
                    self.replay_config(switch_ip)

                    # If replay failed, it stops trying to configure db entries
                    # and sets switch state to inactive so this caller knows
                    # it failed.  If it did fail, we increment the
                    # retry counter else reset it to 0.
                    if self._mdriver.get_switch_ip_and_active_state(
                        switch_ip) == const.SWITCH_INACTIVE:
                        self._mdriver.incr_switch_replay_failure(
                            const.FAIL_CONFIG, switch_ip)
                        LOG.warning("Replay config failed for "
                                    "ip %(switch_ip)s",
                                    {'switch_ip': switch_ip})
                    else:
                        self._mdriver.reset_switch_replay_failure(
                            const.FAIL_CONFIG, switch_ip)
                        self._mdriver.reset_switch_replay_failure(
                            const.FAIL_CONTACT, switch_ip)
                        LOG.info("Replay config successful for "
                            "ip %(switch_ip)s",
                            {'switch_ip': switch_ip})
330390
public void checkConnection() {
        long start = Time.currentTimeMillis();

        while (clientChannel == null) {

            tcpSocketConsumer.checkNotShutdown();

            if (start + timeoutMs > Time.currentTimeMillis())
                try {
                    condition.await(1, TimeUnit.MILLISECONDS);

                } catch (InterruptedException e) {
                    throw new IORuntimeException("Interrupted");
                }
            else
                throw new IORuntimeException("Not connected to " + socketAddressSupplier);
        }

        if (clientChannel == null)
            throw new IORuntimeException("Not connected to " + socketAddressSupplier);
    }
23877
def _CheckConnectionEncoding(cursor):
  """"""
  cur_character_set = _ReadVariable("character_set_connection", cursor)
  if cur_character_set != CHARACTER_SET:
    raise EncodingEnforcementError(
        "Require MySQL character_set_connection of {}, got {}.".format(
            CHARACTER_SET, cur_character_set))
349556
protected synchronized boolean checkConnection()
    {
        if (_connection==null)
        {
            try{
                _connection=_url.openConnection();
            }
            catch(IOException e)
            {
                LogSupport.ignore(log,e);
            }
        }
        return _connection!=null;
    }
1249612
def _check_socket(self, timeout=None):
        """"""
        sock = self.sock
        available_socks = select.select([sock], [sock], [sock], timeout)
        if available_socks[2]:
            raise OSError
        return available_socks
920640
public static void checkConnectionException(SQLException exception,
      MariaDbConnection connection) {
    if (exception.getSQLState() != null) {
      SqlStates state = SqlStates.fromString(exception.getSQLState());
      if (SqlStates.CONNECTION_EXCEPTION.equals(state)) {
        connection.setHostFailed();
        if (connection.pooledConnection != null) {
          connection.pooledConnection.fireConnectionErrorOccured(exception);
        }
      }
    }
  }
289056
public function check()
	{
		// Check if the db connector has been set.
		if (!($this->db instanceof PostgresqlDriver))
		{
			throw new \Exception('Database connection wrong type.');
		}

		// Check if the tables have been specified.
		if (empty($this->from))
		{
			throw new \Exception('ERROR: No Tables Specified');
		}

		return $this;
	}
545491
def _check_connection(self):
        """"""
        if ((self.tcp_disconnect_timer + 2 * self.reconnect_timeout) <
                time.time()):
            self.tcp_disconnect_timer = time.time()
            raise OSError('No response from {}. Disconnecting'.format(
                self.server_address))
        if (self.tcp_check_timer + self.reconnect_timeout) >= time.time():
            return
        msg = Message().modify(
            child_id=255, type=self.const.MessageType.internal,
            sub_type=self.const.Internal.I_VERSION)
        self.add_job(msg.encode)
        self.tcp_check_timer = time.time()
1289831
def handle_connection_error(func):
    """"""
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except device.interface.NotFoundError as e:
            log.error('Connection error (try unplugging and replugging your device): %s', e)
            return 1
    return wrapper
124835
def check_status(self):
        
        log = logging.getLogger("%s.%s" % (self.log_name,
                                           inspect.stack()[0][3]))
        log.setLevel(self.log_level)

        if self.url:
            return True
        try:
            result = requests.get(self.ext_url)
            self.url = self.ext_url
            return True
        except requests.exceptions.ConnectionError:
            pass
        try:
            result = requests.get(self.local_url)
            log.warning("Url '%s' not connecting. Using local_url '%s'" % \
                     (self.ext_url, self.local_url))
            self.url = self.local_url
            return True
        except requests.exceptions.ConnectionError:
            self.url = None
            log.warning("Unable to connect using urls: %s" % set([self.ext_url,
                                                               self.local_url]))
            return False
313809
public boolean isConnectionError(SQLException ex) {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();

        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(this, tc, "isConnectionError", ex);

        // Maintain a set in order to check for cycles
        Set<Throwable> chain = new HashSet<Throwable>();

        boolean stale = super.isConnectionError(ex);
        for (Throwable t = ex; t != null && !stale && chain.add(t); t = t.getCause()) {
            SQLException sqlX = t instanceof SQLException ? (SQLException) t : null;
            if (isTraceOn && tc.isDebugEnabled())
                Tr.debug(this, tc, "checking " + t,
                         sqlX == null ? null : sqlX.getSQLState(),
                         sqlX == null ? null : sqlX.getErrorCode());
            if (sqlX != null)
                stale |= isDataDirectExp(ex)
                         ? staleDDErrorCodes.contains(sqlX.getErrorCode()) || staleDDSQLStates.contains(sqlX.getSQLState())
                         : staleMSErrorCodes.contains(sqlX.getErrorCode());
        }

        if (isTraceOn && tc.isEntryEnabled())
            Tr.exit(this, tc, "isConnectionError", stale);

        return stale;
    }
1013546
protected void checkValid() throws SISessionUnavailableException {

        if (!_parentConnection.isValid()) {

            final SISessionUnavailableException exception = new SISessionUnavailableException(
                    NLS.getString("INVALID_SESSION_CWSIV0200"));
            if (TRACE.isEventEnabled()) {
                SibTr.exception(this, TRACE, exception);
            }
            throw exception;

        }

    }
848036
def is_connection_error(e):
    
    return (isinstance(e, err.InterfaceError) and e.args[0] == "(0, '')") or\
        (isinstance(e, err.OperationalError) and e.args[0] in operation_error_codes.values())