mongodbsymfonyxdebugphp-mongodbmongo-c-driver

The parameter: client, in function mongoc_client_get_uri, cannot be NULL


I'm trying to set up a phpfpm, nginx and mongodb stack in docker. I have a strange problem, which only occurs when capturing the request with xdebug. When the request is not captured, the result is as expected, if I try to debug a request, I get this error in the php container:

"The parameter: client, in function mongoc_client_get_uri, cannot be NULL WARNING: [pool www] child 219 exited on signal 6 (SIGABRT) after 171.996764 seconds from start"

This error occurs when trying to create the mongo Manager in vendor/mongodb/mongodb/src/Client.php with this code:

$this->manager = new Manager($uri, $uriOptions, $driverOptions);

The uri passed is correct:

$uri=mongodb://user:pass@mongodb:27017/database

Where user, pass and database have the appropriate values. My mongo php config:

php -i | grep -i "mongo"
mongodb
MongoDB support => enabled
MongoDB extension version => 1.19.3
MongoDB extension stability => stable
libmongoc bundled version => 1.27.2
libmongoc SSL => enabled
libmongoc SSL library => OpenSSL
libmongoc crypto => enabled
libmongoc crypto library => libcrypto
libmongoc crypto system profile => disabled
libmongoc SASL => enabled
libmongoc SRV => enabled
libmongoc compression => enabled
libmongoc compression snappy => enabled
libmongoc compression zlib => enabled
libmongoc compression zstd => enabled
libmongocrypt bundled version => 1.10.0
libmongocrypt crypto => enabled
libmongocrypt crypto library => libcrypto
mongodb.debug => stderr => stderr

My php version:

php -v
PHP 8.2.20 (cli) (built: Jul  2 2024 03:47:15) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.20, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.20, Copyright (c), by Zend Technologies
    with Xdebug v3.3.2, Copyright (c) 2002-2024, by Derick Rethans

Example code:

<?php
require '../vendor/autoload.php';

$uri = 'mongodb://user:pass@mongodb:27017/database';
try {
    $client = new MongoDB\Client($uri, ['readPreference' => 'primaryPreferred']);
    echo "Connection successful!";
} catch (Exception $e) {
    echo 'Error connecting to MongoDB: ' . $e->getMessage();
}

Phpfpm log when request is not captured and successful:

2024-07-22 13:54:54 NOTICE: PHP message: Xdebug: [Step Debug] Could not connect to debugging client. Tried: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port).
2024-07-22 13:54:54 [2024-07-22T11:54:54.373389+00:00]     PHONGO: DEBUG   > Connection string: 'mongodb://user:pass@mongodb:27017/database'
2024-07-22 13:54:54 [2024-07-22T11:54:54.373647+00:00]     PHONGO: DEBUG   > Creating Manager, phongo-1.19.3[stable] - mongoc-1.27.2(bundled), libbson-1.27.2(bundled), php-8.2.20
2024-07-22 13:54:54 [2024-07-22T11:54:54.373702+00:00]     PHONGO: DEBUG   > Setting driver handshake data: { name: 'ext-mongodb:PHP / PHPLIB ', version: '1.19.3 / 1.19.1 ', platform: 'PHP 8.2.20 ' }
2024-07-22 13:54:54 [2024-07-22T11:54:54.373765+00:00]     client: TRACE   > ENTRY: mongoc_client_new_from_uri_with_error():1001
2024-07-22 13:54:54 [2024-07-22T11:54:54.373886+00:00]     mongoc: TRACE   > ENTRY: mongoc_topology_description_init():79
2024-07-22 13:54:54 [2024-07-22T11:54:54.373984+00:00]     mongoc: TRACE   >  EXIT: mongoc_topology_description_init():97
2024-07-22 13:54:54 [2024-07-22T11:54:54.374060+00:00]     mongoc: TRACE   > ENTRY: mongoc_server_description_init():121
2024-07-22 13:54:54 172.18.0.4 -  22/Jul/2024:13:54:54 +0200 "GET /test.php" 200
2024-07-22 13:54:54 [2024-07-22T11:54:54.374125+00:00]     mongoc: TRACE   >  EXIT: mongoc_server_description_init():149
2024-07-22 13:54:54 [2024-07-22T11:54:54.374172+00:00]    cluster: TRACE   > ENTRY: mongoc_cluster_init():2505
2024-07-22 13:54:54 [2024-07-22T11:54:54.374197+00:00]    cluster: TRACE   >  EXIT: mongoc_cluster_init():2528
2024-07-22 13:54:54 [2024-07-22T11:54:54.374202+00:00]     client: TRACE   >  EXIT: mongoc_client_new_from_uri_with_error():1030
2024-07-22 13:54:54 [2024-07-22T11:54:54.374226+00:00]     PHONGO: DEBUG   > Created client with hash: a:4:{s:3:"pid";i:223;s:3:"uri";s:56:"mongodb://user:pass@mongodb:27017/database";s:7:"options";a:1:{s:14:"readPreference";s:16:"primaryPreferred";}s:13:"driverOptions";a:1:{s:6:"driver";a:2:{s:4:"name";s:6:"PHPLIB";s:7:"version";s:6:"1.19.1";}}}
2024-07-22 13:54:54 [2024-07-22T11:54:54.374264+00:00]     PHONGO: DEBUG   > Stored persistent client with hash: a:4:{s:3:"pid";i:223;s:3:"uri";s:56:"mongodb://user:pass@mongodb:27017/database";s:7:"options";a:1:{s:14:"readPreference";s:16:"primaryPreferred";}s:13:"driverOptions";a:1:{s:6:"driver";a:2:{s:4:"name";s:6:"PHPLIB";s:7:"version";s:6:"1.19.1";}}}
2024-07-22 13:54:54 [2024-07-22T11:54:54.374396+00:00]     PHONGO: DEBUG   > Not destroying persistent client for Manager

Phpfpm log when request is captured and fails:

2024-07-22 13:59:49 The parameter: client, in function mongoc_client_get_uri, cannot be NULL
2024-07-22 13:59:49 [22-Jul-2024 13:59:49] WARNING: [pool www] child 227 exited on signal 6 (SIGABRT) after 1708.727192 seconds from start
2024-07-22 13:59:49 [22-Jul-2024 13:59:49] NOTICE: [pool www] child 229 started

Without capturing the request the result is "Connection successful!". Capturing the request gives the aforementioned error. Any idea what's going on or how to investigate further?

I have also activated the debug of the MongoDB Extension php extension but I cannot see why this error occurs. I have tried different versions of the mongoc driver, the php extension and the mongo database version and verified that they are compatible.

Thank you.


Solution

  • Solved. After wasting a week ruling out problems and trying different versions of the different libraries, it was a problem with the PHPSTORM configuration files. Something had gone wrong and no matter how many times I changed the configuration it didn't work. The solution was to delete the .idea folder, configure the server again and everything was working.