Magento: Algolia Search Queue Runner Indexer throws an exception

Hi,

I have a problem reindexing algolia_queue_runner with php -f indexer.php -- -reindex algolia_queue_runner on a Magento 1.9.3.10 Shop.
After ca. 20 seconds, the indexer throws 2-3 exceptions. I have documented the issue on the module page on GitHub:

https://github.com/algolia/algoliasearch-magento/issues/1087

All the other indexes are running fine, it’s just this one that is causing the full reindex process to break.

I am using the module version 1.14.1 on Magento 1.9.3.10 patched on PHP 7.2. One important detail: Magento accesses the MySQL database via socket connection (even though the exception says “localhost”: maybe this is the problem?). I could reproduce this issue nowhere else.

The hosting support told me that the socket is configured correctly on the server: they run both MySQL and MariaDB, the connection via localhost reaches MariaDB, via socket MySQL. Apparently, the indexer is trying to access the wrong service.

I am looking forward to any feedback on this issue, since now the search is unusable!

After a deep debugging session, I came to analyze the content of $dsn in
magento/lib/Zend/Db/Adapter/Pdo/Abstract.php, Line 123, where the connection parameters are set. This way I could analyze the string by adding the following line:

echo "$dsn, {$this->_config['username']}, {$this->_config['password']}\n";

The indexer performs 3 calls: the first one is correct, the last two contain an empty host= parameter that breaks everything causing the “Access Denied” error:

magento/shell$ php indexer.php --reindex algolia_queue_runner
mysql:dbname=magento;port=3307;initStatements=SET NAMES utf8;model=mysql4;type=pdo_mysql;pdoType=;active=1;unix_socket=/tmp/mysql5.sock, username, password
mysql:dbname=magento;port=3307;initStatements=SET NAMES utf8;model=mysql4;type=pdo_mysql;pdoType=;active=1;unix_socket=/tmp/mysql5.sock;host=, username, password
mysql:dbname=magento;port=3307;initStatements=SET NAMES utf8;model=mysql4;type=pdo_mysql;pdoType=;active=1;unix_socket=/tmp/mysql5.sock;host=, username, password

To test if this was the problem, I replaced ;host= with ;host=localhost in the connection string:

$dsn=str_replace(';host=', ';host=localhost', $dsn);

After this replacement, the indexer worked as expected - this time, I got only 2 requests to the database:

magento/shell$ php indexer.php --reindex algolia_queue_runner
mysql:dbname=magento;port=3307;initStatements=SET NAMES utf8;model=mysql4;type=pdo_mysql;pdoType=;active=1;unix_socket=/tmp/mysql5.sock, username, password
mysql:dbname=magento;port=3307;initStatements=SET NAMES utf8;model=mysql4;type=pdo_mysql;pdoType=;active=1;unix_socket=/tmp/mysql5.sock;host=localhost, username, password
Algolia Search Queue Runner index was rebuilt successfully in 00:00:19

Of course this cannot be a definitive solution to the problem, since I can’t just hack the core Magento PDO-Adapter in the live shop without knowing the possible consequences!

Setting the following parameters in the php.ini didn’t help as well (I am still getting host= in the connection string):

mysql.default_host="localhost"
mysqli.default_host="localhost"
mysql.default_port=3307
mysqli.default_port=3307

The question is: why is this particular indexer establishing two different connections with the database?
Where and how can this be fixed?

Hi,
suggest you throw an exception in the the adapter if host is empty to see the code path of the broken operation?