cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot connect to any server on alias: default with Uris: ('')

aerfan
Node Link

I'm using neo4j with "laudis/neo4j-php-client": "^2.8" package
And this error occurred suddenly with error message:
Cannot connect to any server on alias: default with Uris: ('')
And here is my code to connect to neo4j DB Aura using bolt

public static function RunStatement($statement)
{
if (Config::get('neo4j_connection')) {
$client = Config::get('neo4j_connection');
} else {
try {
$client = self::createClientBuilder();
} catch (Exception $e) {
captureMessage($e->getMessage());
$client = self::createClientBuilder();
}
}

try {
return self::execute($client, $statement);
} catch (Exception $e) {
captureMessage($e->getMessage());
return self::execute($client, $statement);
}
}
private static function createClientBuilder(): ClientInterface
{
$auth = Authenticate::basic(env('DB_USERNAME_NEO4J'), env('DB_PASSWORD_NEO4J'));
$client = ClientBuilder::create()
->withDriver('default', env('DB_BOLT_NEO4J'), $auth)
->withDefaultTransactionConfiguration(TransactionConfiguration::default()
->withTimeout(300)
)
->build();

Config::set('neo4j_connection', $client);
return $client;
}
 private static function execute($client, $statement)
{
return $client->writeTransaction(static function (TransactionInterface $tsx) use ($statement) {
return $tsx->run($statement->getText());
});
}

Please advise to solve this issue

 

3 REPLIES 3

ghlen
Node

Hello @aerfan !

Can you please confirm the 'DB_BOLT_NEO4J', 'DB_USERNAME_NEO4J' and 'DB_PASSWORD_NEO4J' is correctly loaded into the environment? I have a feeling these are just null or an empty string.

Kind regards,

Ghlen

Hello @ghlen,  Thanks for your reply.

I have checked them and these keys are correctly loaded 
This issue occurred about 15 times only on a production server and disappeared and not happened again till now, But when it happened the server CPU was completely used and the server crashed.
  

aerfan_0-1674546511103.png

 

ghlen
Node

Hmm, interesting. This sounds like an availability problem. The Client and driver have some tools to mitigate this.

Autorouting only starts works only by fetching the routing table first. That means you can't do routing if the preconfigured initial server is down.

There are three ways of solving this:
- Provide a Psr SimpleCache implementation that keeps the data outside a PHP process (e.g. a file or Redis driver). That way, it won't ask for the routing table for every request. It also boosts performance in general. Use the `DriverConfig::withCache` method to configure this.
- Set up DNS, so the initial server address returns multiple A and AAAA records pointing to different servers in the cluster. The driver can handle this, which is why it errors that it did not find a server of an array of URIs.
- Use the driver fallback feature in the Client. Leverage this functionality by adding multiple drivers on the same alias to the client builder. You can use priority numbers to influence the order.

If the problem persists (e.g. all servers are down), there is an actual scaling problem, and you should look to optimize queries and traffic and increase server availability.

These features are there but have yet to be documented because I am short on time.

If it does not work or the server setup details are too private to discuss here, you can always reach out to me via email at ghlen@nagels.tech.

Good luck!