If the connection to redsmin just closed, try to reconnect
@param  {Error} err
@param {Boolean} true if after the on close the Endpoint should not reconnect
332023
function(sourceWasAnError, shouldNotReconnect) {
      log.error("[Endpoint] Connection closed " + (sourceWasAnError ? 'because of an error:' + sourceWasAnError : ''));

      this.connected = false;
      this.handshaken = false;
      this.connecting = false;

      if (!shouldNotReconnect) {
        log.debug('onClose():: reconnecting...');
        this.handshakenBackoff.reset();
        this.reconnectBackoff.backoff();
      } else {
        log.debug('onClose():: don\'t reconnect');
        this.handshakenBackoff.reset();
        this.reconnectBackoff.reset();
      }

      this.emit('close', sourceWasAnError);
    }
26309
def safely
    safe_connect

    retries = 0

    begin
      yield

    rescue Errno::ECONNABORTED,
           Errno::ECONNRESET,
           Errno::ENOTCONN,
           Errno::EPIPE,
           Errno::ETIMEDOUT,
           IOError,
           Net::IMAP::ByeResponseError,
           OpenSSL::SSL::SSLError => e

      raise unless (retries += 1) <= @options[:max_retries]

      warning "#{e.class.name}: #{e.message} (reconnecting)"

      reset
      sleep 1 * retries
      safe_connect
      retry

    rescue Net::IMAP::BadResponseError,
           Net::IMAP::NoResponseError,
           Net::IMAP::ResponseParseError => e

      raise unless (retries += 1) <= @options[:max_retries]

      warning "#{e.class.name}: #{e.message} (will retry)"

      sleep 1 * retries
      retry
    end

  rescue Larch::Error => e
    raise

  rescue Net::IMAP::Error => e
    raise Error, "#{e.class.name}: #{e.message} (giving up)"

  rescue => e
    raise FatalError, "#{e.class.name}: #{e.message} (cannot recover)"
  end
267068
function onReferralError(err) {
            log.error(err, '[%s] An error occurred chasing the LDAP referral on %s (%j)',
                     (err || {}).errno, referralBaseDn, opts);
            removeReferral(referralClient);
          }
991769
def ShouldRetry(self, exception):
        
        if not self.connection_policy.EnableEndpointDiscovery:
            return False

        if self.failover_retry_count >= self.Max_retry_attempt_count:
            return False

        self.failover_retry_count += 1

        if self.location_endpoint:
            if _OperationType.IsReadOnlyOperation(self.request.operation_type):
                #Mark current read endpoint as unavailable
                self.global_endpoint_manager.mark_endpoint_unavailable_for_read(self.location_endpoint)
            else:
                self.global_endpoint_manager.mark_endpoint_unavailable_for_write(self.location_endpoint)

        # set the refresh_needed flag to ensure that endpoint list is
        # refreshed with new writable and readable locations
        self.global_endpoint_manager.refresh_needed = True
        
        # clear previous location-based routing directive
        self.request.clear_route_to_location()

        # set location-based routing directive based on retry count
        # simulating single master writes by ensuring usePreferredLocations
        # is set to false
        self.request.route_to_location_with_preferred_location_flag(self.failover_retry_count, False)
        
        # Resolve the endpoint for the request and pin the resolution to the resolved endpoint
        # This enables marking the endpoint unavailability on endpoint failover/unreachability
        self.location_endpoint = self.global_endpoint_manager.resolve_service_endpoint(self.request)
        self.request.route_to_location(self.location_endpoint)
        return True
828799
private void actuallyReconnect() {
        if (((null == signalingChannel) || !signalingChannel.connected) && reconnect) {
            if (connectionInProgress) {
                // The client app must have initiated a connection manually during the timeout period. Try again later
                performReconnect();
            } else {
                Log.d(TAG, "Trying to reconnect...");
                connect(localEndpointID, applicationID, reconnect, presence, appContext, new ConnectCompletionListener() {
                    @Override
                    public void onError(final String errorMessage) {
                        // A REST API call failed. Socket errors are handled in the onError callback
                        new Handler(Looper.getMainLooper()).post(new Runnable() {
                            @Override
                            public void run() {
                                Listener listener = listenerReference.get();
                                if (null != listener) {
                                    listener.onError(RespokeClient.this, errorMessage);
                                }
                            }
                        });

                        // Try again later
                        performReconnect();
                    }
                });
            }
        }
    }
1335845
function autoReconnect(options, connectionListener)
{
	var reconnectInterval = getOption(options, 'reconnectInterval', 5000);

	var reconnector = new events.EventEmitter();

	function reconnect()
	{
		var client = connect(options);
		var isReconnecting = false;
		
		function tryReconnecting()
		{
			if ( !isReconnecting )
			{
				isReconnecting = true;
				reconnector.emit('close');
			}
		}

		client.on('connect', () => {
			connectionListener(client);
		});

		client.on('close', () => {
			tryReconnecting();
		});

		client.on('error', (e) => {
			tryReconnecting();
		});
	}

	reconnector.on('close', () => {
		setTimeout(() => reconnector.emit('reconnect'), reconnectInterval);
	});

	reconnector.on('reconnect', () => {
		reconnect();
	});
	
	reconnect();
}
846175
def _on_closed(self):
        """"""
        LOGGER.error('Redis connection closed')
        self.connected = False
        self._on_close()
        self._stream = None
1096166
def reconnect
      tries = 0
      begin
        redis.synchronize do |client|
          client.reconnect
        end
      rescue Redis::BaseConnectionError
        if (tries += 1) <= 3
          log "Error reconnecting to Redis; retrying"
          sleep(tries)
          retry
        else
          log "Error reconnecting to Redis; quitting"
          raise
        end
      end
    end
9652
def connection_lost(self, exc):
        """"""
        if exc:
            log.exception('disconnected due to exception')
        else:
            log.info('disconnected because of close/abort.')
        if self.disconnect_callback:
            self.disconnect_callback(exc)
1133473
function onOutgoingError(err) {
    if (cb) {
      cb(err, req, socket);
    } else {
      server.emit('error', err, req, socket);
    }
    socket.end();
  }
396484
def is_retryable(err):
    
    if isinstance(err, ConnectionClosed):
        # NB: only retryable if we're not mid-streaming
        if err.mid_stream:
            return False
        else:
            return True
    elif isinstance(err, socket.error):
        code = err.args[0]
        return code in CONN_CLOSED_ERRORS
    else:
        return False
785453
function fail(err, cbErr)
    {
      if(!err) return; // only catch errors
      log.warn('chat fail',err);
      chat.err = err;
      // TODO error inbox/outbox
      if(typeof cbErr == 'function') cbErr(err);
      readyUp(err);
    }
1286272
def on_close(data, *args)
      options = args.extract_options!
      options[:code] ||= (data && data.code) || '1000'

      disconnect
      fail SlackBotManager::ConnectionRateLimited if %w(1008 429).include?(options[:code].to_s)
    end
1083429
function proxyError(err) {
    errState = true;

    //
    // Emit an `error` event, allowing the application to use custom
    // error handling. The error handler should end the response.
    //
    if (self.emit('proxyError', err, req, res)) {
      return;
    }

    res.writeHead(500, { 'Content-Type': 'text/plain' });

    if (req.method !== 'HEAD') {
      //
      // This NODE_ENV=production behavior is mimics Express and
      // Connect.
      //
      if (process.env.NODE_ENV === 'production') {
        res.write('Internal Server Error');
      }
      else {
        res.write('An error has occurred: ' + JSON.stringify(err));
      }
    }

    try { res.end() }
    catch (ex) { console.error("res.end error: %s", ex.message) }
  }
741835
function connectError(error)
	{
		if (error == evothings.easyble.error.DISCONNECTED)
		{
			showMessage('Device disconnected')
		}
		else
		{
			showMessage('Connect error: ' + error)
		}
	}
1257954
async def _reconnect(self, last_error):
        
        self._log.debug('Closing current connection...')
        await self._connection.disconnect()

        await helpers._cancel(
            self._log,
            send_loop_handle=self._send_loop_handle,
            recv_loop_handle=self._recv_loop_handle
        )

        # TODO See comment in `_start_reconnect`
        # Perhaps this should be the last thing to do?
        # But _connect() creates tasks which may run and,
        # if they see that reconnecting is True, they will end.
        # Perhaps that task creation should not belong in connect?
        self._reconnecting = False

        # Start with a clean state (and thus session ID) to avoid old msgs
        self._state.reset()

        retries = self._retries if self._auto_reconnect else 0
        for attempt in retry_range(retries):
            try:
                await self._connect()
            except (IOError, asyncio.TimeoutError) as e:
                last_error = e
                self._log.info('Failed reconnection attempt %d with %s',
                               attempt, e.__class__.__name__)

                await asyncio.sleep(self._delay)
            except Exception as e:
                last_error = e
                self._log.exception('Unexpected exception reconnecting on '
                                    'attempt %d', attempt)

                await asyncio.sleep(self._delay)
            else:
                self._send_queue.extend(self._pending_state.values())
                self._pending_state.clear()

                if self._auto_reconnect_callback:
                    self._loop.create_task(self._auto_reconnect_callback())

                break
        else:
            self._log.error('Automatic reconnection failed {} time(s)'
                            .format(attempt))
            await self._disconnect(error=last_error.with_traceback(None))
1301320
function(err) {
    notify.onError({
        title: "Error: " + err.plugin,
        subtitle: "<%= file.relative %>",
        message: "<%= error.message %>",
        sound: "Beep",
    })(err);
    console.log(err.toString())
    this.emit('end');
}