Endless connection

@param $connectionParams
@throws \Doctrine\DBAL\DBALException
489424
protected function persistentConnect($connectionParams)
    {
        $config = new \Doctrine\DBAL\Configuration();
//          $logger = new Doctrine\DBAL\Logging\EchoSQLLogger();
//          $config->setSQLLogger($logger);

        $connLimit = 3; // Max connection attempts.
        $counter = 0; // Connection attempts counter.

        while (true) {
            try {
                /** @var \Doctrine\DBAL\Connection connection */
                $this->connection = $this->getConnection($connectionParams, $config);
                // to generate DBALException if no connection
                $this->connection->ping();
                break;
            } catch (\Doctrine\DBAL\DBALException $e) {
                $this->connection = null;
                $counter++;

                if ($counter === $connLimit){
                    // Connection attempts exceeded.
                    throw $e;
                }
            }
        }
    }
444523
private function notPersistentConnect(\stdClass $connectionOptions)
    {
        if (!$this->connection->connect(
            $connectionOptions->host,
            $connectionOptions->port,
            $connectionOptions->timeout,
            null,
            $connectionOptions->retryDelay
        )) {
            throw new RedisConnectionException(
                "Can't connect to redis server with config: " . var_export($connectionOptions, true)
            );
        };
    }
396784
public function setConnection($connectionConfig)
    {
        self::$config = static::parseUrl($connectionConfig);

        try {
            return  static::createConnection(self::$config);
        } catch (\PDOException $e) {
            throw new \Exception($e->getMessage());
        }
    }
367073
public function createConnection(array $params, Configuration $config = null, EventManager $eventManager = null, array $mappingTypes = [])
    {
        if (isset($params['dbname'])) {
            $dbName = $this->getDbNameFromEnv($params['dbname']);
        } else {
            $dbName = $this->getDbNameFromEnv($params['master']['dbname']);
        }

        if ('pdo_sqlite' === $params['driver']) {
            if (isset($params['path'])) {
                $params['path'] = str_replace('__DBNAME__', $dbName, $params['path']);
            }

            if (isset($params['master']['path'])) {
                $params['master']['path'] = str_replace('__DBNAME__', $dbName, $params['master']['path']);
            }

            if (!empty($params['slaves'])) {
                foreach ($params['slaves'] as &$slave) {
                    $slave['path'] = str_replace('__DBNAME__', $dbName, $slave['path']);
                }
            }
        } else {
            $params['dbname'] = $dbName;
        }

        return parent::createConnection($params, $config, $eventManager, $mappingTypes);
    }
1098853
protected function createConnection($params)
    {
        $credentials = '';
        if (isset($params['password'])) {
            $credentials = ':' . $params['password'];
        }
        if (isset($params['user'])) {
            $credentials = $params['user'] . $credentials . '@';
        }

        $database = '';
        if (isset($params['dbname'])) {
            $database = '/' . $params['dbname'];
        }

        $server = sprintf(
            'mongodb://%s%s:%s%s',
            $credentials,
            (isset($params['host']) ? $params['host'] : 'localhost'),
            (isset($params['port']) ? $params['port'] : '27017'),
            $database
        );

        $options = [];
        if (!empty($params['options'])) {
            $options = $params['options'];
        }

        return new Connection($server, $options);
    }
122480
public function setDBParams(array $dbParams = array())
    {
        if (defined('SQLDBENGINE')) {
            $this->params = [
                'DBSCHEMA' => SQLDBSCHEMA,
                'DBNAME' => SQLDBNAME,
                'DBPREFIX' => SQLDBPREFIX
            ];

            // Allow params to be over-ridable.
            $this->params['DBHOST'] = (isset($dbParams['host']) ? $dbParams['host'] : SQLDBHOST);
            $this->params['DBUSER'] = (isset($dbParams['username']) ? $dbParams['username'] : SQLDBUSERNAME);
            $this->params['DBPASSWORD'] = (isset($dbParams['password']) ? $dbParams['password'] : SQLDBPASSWORD);
            $this->params['DBENGINE'] = (isset($dbParams['engine']) ? $dbParams['engine'] : SQLDBENGINE);
        } else {
            $params = getenv('BEHAT_ENV_PARAMS');

            if (! $params) {
                throw new \Exception('"BEHAT_ENV_PARAMS" environment variable was not found.');
            }

            $params = explode(';', $params);

            foreach ($params as $param) {
                list($key, $val) = explode(':', $param);
                $this->params[$key] = trim($val);
            }
        }

        return $this;
    }
1028627
public function flushQueue(string $connectionName = null)
    {
        if (empty($this->queues)) {
            return;
        }

        if ($connectionName === null) {
            foreach ($this->queues as $queueConnectionName => $queue) {
                $this->flushQueueItem($queueConnectionName, $queue);
            }
        } elseif (array_key_exists($connectionName, $this->queues)) {
            $this->flushQueueItem($connectionName, $this->queues[$connectionName]);
        }
    }
733217
public function handle(ConnectionInterface $incoming)
    {
        $this->incoming = $incoming;

        $this->incoming->on('data', [$this, 'handleData']);
        $this->incoming->on('close', function () {
            $this->connectionOpen = false;
        });

        $this->start = microtime(true);
        $this->requestSentAt = microtime(true);
        $this->getNextSlave();

        if ($this->maxExecutionTime > 0) {
            $this->maxExecutionTimer = $this->loop->addTimer($this->maxExecutionTime, [$this, 'maxExecutionTimeExceeded']);
        }
    }
74659
function checkinConnection(\Plasma\DriverInterface $driver): void {
        if($driver->getConnectionState() !== \Plasma\DriverInterface::CONNECTION_UNUSABLE && !$this->goingAway) {
            $this->connections->add($driver);
            $this->busyConnections->delete($driver);
        }
    }
246367
public function connection(?string $using, Closure $callback, array $options = []): void
    {
        $repository = $this->app->make('config');

        if (\is_null($using)) {
            $using = $repository->get('database.default');
        }

        $config = $repository->get("database.connections.{$using}", null);

        if (\is_null($config)) {
            throw new InvalidArgumentException("Database connection [{$using}] is not available.");
        }

        Arr::set($this->config, 'connection', [
            'name' => "{$using}_{id}",
            'template' => $config,
            'resolver' => $callback,
            'options' => $options,
        ]);
    }
213499
public function commit()
    {
        if ($this->transactionLevel === 0) {
            throw ConnectionException::noActiveTransaction();
        }

        if ($this->transactionLevel === 1) {
            $queryDebugger = $this->createQueryDebugger('COMMIT TRANSACTION');
            $this->getDriverConnection()->commit();
            $this->debugQuery($queryDebugger);
        } else {
            $this->exec($this->getPlatform()->getReleaseSavepointSQLQuery($this->generateSavepointName()));
        }

        $this->transactionLevel--;
    }
90007
public function execute($params = null) {
        $query   = SqlQuery::setParams($this->query, $params !== null ? $params : $this->params);
        $request = $this->authStrategy->transformRequest($this->mysqlToRequest->transform($query));

        try {
            $response     = $this->restClient->send($request);
            $result       = new Result($query, $request->getMethod(), $response, $this->options);
            $this->result = $result->get();
            $this->id     = $result->id();

            return true;
        } catch(RequestFailedException $e) {
            // as the error handling proposed by doctrine
            // does not work, we use the way of PDO_mysql
            // which just throws the possible errors
            throw new DoctrineRestDriverException($e->getMessage(), $e->getCode());
        }
    }
154430
private function closeConnections()
    {
        if (!$this->container->hasParameter('doctrine_phpcr.sessions')) {
            return;
        }

        foreach ($this->container->getParameter('doctrine_phpcr.sessions') as $id) {
            if ($this->container instanceof IntrospectableContainerInterface && !$this->container->initialized($id)) {
                continue;
            }

            $session = $this->container->get($id);
            if (!$session instanceof Session) {
                return;
            }

            $session->getTransport()->logout();
        }
    }
994051
public function setConnectionTimeout($connectionTimeout) {
		if (!is_numeric($connectionTimeout) || $connectionTimeout < 0) {
			throw new \InvalidArgumentException('Timeout value must be numeric and a non-negative number.');
		}

		$this->connectionTimeout = $connectionTimeout;
		return $this;
	}
264850
protected static function _connection(& $connection)
	{
		if (static::isString($connection))
			$connection = static::connection($connection);

		if (!$connection instanceof \PDO)
			throw new \InvalidArgumentException("invalid connection");
	}
87303
public function setActiveConnections($connections)
    {
        if (!is_array($connections)) {
            $connections = explode(',', $connections);
        }

        // Sanitize and set connections
        $filtered = array_filter($connections, [$this, 'isValidConnection']);
        if (!$filtered) {
            throw new ConnectionException('Invalid connection(s): '.implode(', ', $connections));
        }

        $this->available = $this->getConnections()->map(function (ConnectionInterface $connection) use ($connections) {
            $connectionKey = $connection->getConnectionKey();
            $handle = $connectionKey->toHandle();

            $connection->setActive(in_array($handle, $connections, true) || in_array($connectionKey->name, $connections, true));
            $connection->setCurrent(false);

            return $connection;
        });
    }
1359554
private function connect() {
    // connect
    if (isset($this->connectionParams['dbType']) && isset($this->connectionParams['dbHostName']) &&
      isset($this->connectionParams['dbUserName']) && isset($this->connectionParams['dbPassword']) &&
      isset($this->connectionParams['dbName'])) {

      $dbType = strtolower($this->connectionParams['dbType']);
      $this->isFileDB = $dbType == 'sqlite' && strtolower($this->connectionParams['dbName']) != ':memory:';

      $this->connId = join(',', [$this->connectionParams['dbType'], $this->connectionParams['dbHostName'],
          $this->connectionParams['dbUserName'], $this->connectionParams['dbPassword'], $this->connectionParams['dbName'],
          // make sure that the sequence mapper uses it's own connection for separate transaction management
          (!$this->isFileDB && $this->getType() == $this->getSequenceMapper()->getType())
      ]);

      // reuse an existing adapter if possible
      if (isset(self::$adapters[$this->connId])) {
        $this->adapter = self::$adapters[$this->connId];
      }
      else {
        try {
          $charSet = isset($this->connectionParams['dbCharSet']) ?
                  $this->connectionParams['dbCharSet'] : 'utf8';

          // create new connection
          $pdoParams = [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION];
          // driver specific
          switch ($dbType) {
            case 'mysql':
              $pdoParams[PDO::MYSQL_ATTR_USE_BUFFERED_QUERY] = true;
              $pdoParams[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES ".$charSet;
              break;
            case 'sqlite':
              if (!$this->isFileDB) {
                $pdoParams[PDO::ATTR_PERSISTENT] = true;
              }
              else {
                $this->connectionParams['dbName'] = FileUtil::realpath(WCMF_BASE.$this->connectionParams['dbName']);
              }
              break;
          }

          $params = [
            'hostname' => $this->connectionParams['dbHostName'],
            'username' => $this->connectionParams['dbUserName'],
            'password' => $this->connectionParams['dbPassword'],
            'database' => $this->connectionParams['dbName'],
            'driver' => 'Pdo_'.ucfirst($this->connectionParams['dbType']),
            'driver_options' => $pdoParams
          ];

          if (!empty($this->connectionParams['dbPort'])) {
            $params['port'] = $this->connectionParams['dbPort'];
          }
          $this->adapter = new Adapter($params);

          // store the connection for reuse
          self::$adapters[$this->connId] = $this->adapter;
        }
        catch(\Exception $ex) {
          throw new PersistenceException("Connection to ".$this->connectionParams['dbHostName'].".".
            $this->connectionParams['dbName']." failed: ".$ex->getMessage());
        }
      }
      // get database prefix if defined
      if (isset($this->connectionParams['dbPrefix'])) {
        $this->dbPrefix = $this->connectionParams['dbPrefix'];
      }
    }
    else {
      throw new IllegalArgumentException("Wrong parameters for constructor.");
    }
  }