mongodb / mongo-php-library

The Official MongoDB PHP library

Home Page:https://mongodb.com/docs/php-library/current/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when using with serverless instance

notf0und opened this issue · comments

Bug Report

When using the library with an atlas serverless instance, the library returns the following error:

context : {
    exception : {
        class: "MongoDB\\Driver\\Exception\\RuntimeException",
        message: "Failed to get handshake server description: Driver attempted to initialize in load balancing mode, but the server does not support this mode.","
        code: 0,
        file: "/var/task/vendor/mongodb/mongodb/src/functions.php:299"
    }
} 

The issue is not consistent since sometimes works, sometimes not, when it stops working, most likely I have to restart the php server and it fixes the issue.

Environment

Tried on different environments, all with the same results.

Environment 1:
Ubuntu Linux 21.04
PHP 7.4 & 8.1
Driver version: 1.11
Extension version: 1.12
nginx/1.18.0

Environment 2
Laravel Vapor (Amazon lambda)
PHP 8.0
Driver version: 1.11
Extension version: 1.12

I'm using MongoDB Atlas with the following configuration:

Type: Serverless Instance
Region: AWS / ap-southeast-2
Version 5.2.0

Output of php -i | grep -E 'mongodb|libmongoc|libbson'

libbson bundled version => 1.20.0
libmongoc bundled version => 1.20.0
libmongoc SSL => enabled
libmongoc SSL library => OpenSSL
libmongoc crypto => enabled
libmongoc crypto library => libcrypto
libmongoc crypto system profile => disabled
libmongoc SASL => disabled
libmongoc ICU => enabled
libmongoc compression => enabled
libmongoc compression snappy => disabled
libmongoc compression zlib => enabled
libmongoc compression zstd => disabled
libmongocrypt bundled version => 1.3.0
libmongocrypt crypto => enabled
libmongocrypt crypto library => libcrypto
mongodb.debug => no value => no value
mongodb.mock_service_id => Off => Off
DB_CONNECTION => mongodb_serverless
DB_DSN => mongodb+srv://USER:PASS@INSTANCE.1gnpb.mongodb.net/DBNAME?retryWrites=true&w=majority
$_SERVER['DB_CONNECTION'] => mongodb_serverless
$_SERVER['DB_DSN'] => mongodb+srv://USER:PASS@INSTANCE.1gnpb.mongodb.net/DBNAME?retryWrites=true&w=majority
$_ENV['DB_CONNECTION'] => mongodb_serverless
$_ENV['DB_DSN'] => mongodb+srv://USER:PASS@INSTANCE.1gnpb.mongodb.net/DBNAME?retryWrites=true&w=majority

My composer contains the following libraries for more reference:

laravel/framework: v8.83.0
mongodb/mongodb: 1.11.0
jenssegers/mongodb: 3.8.4

This error is caused by CDRIVER-4207, which was released in libmongoc 1.20.1. I neglected to make a patch release of ext-mongodb 1.12.x with an update to our bundled libmongoc sources, since I've been focusing on the upcoming 1.13.0 release, which will include libmongoc 1.21.0.

That said, I can publish a 1.12.1 patch release with that update this week and will follow-up in this thread after I do so.

If you need a more immediate solution, you can also install libmongoc 1.20.1 or 1.21.0 as a system library and then build the extension from source while specifying --with-mongodb-system-libs=yes as a configure parameter.


Edit: got my versions numbers mixed up. The next ext-mongodb patch release would be 1.12.1. The most recent libmongoc release is 1.21.0, which includes the necessary fix from 1.20.1.

First of all I wanna say thank you for your library and for giving support to it. It's an amazing tool that made my life/work much better and easier.

In regards to the solution provided, I have attempted to install libmongoc 1.21.0 (was not able to find 1.21.1) and build the extension from source, which seems has work so far since after execute php -i | grep -E 'mongodb|libmongoc|libbson' i can see:

/etc/php/7.4/cli/conf.d/20-mongodb.ini,
mongodb
libbson headers version => 1.21.0
libbson library version => 1.21.0
libmongoc headers version => 1.21.0
libmongoc library version => 1.21.0
libmongoc SSL => enabled
libmongoc SSL library => OpenSSL
libmongoc crypto => enabled
libmongoc crypto library => libcrypto
libmongoc crypto system profile => disabled
libmongoc SASL => disabled
libmongoc ICU => disabled
libmongoc compression => enabled
libmongoc compression snappy => disabled
libmongoc compression zlib => enabled
libmongoc compression zstd => disabled
libmongocrypt => disabled
mongodb.debug => no value => no value
mongodb.mock_service_id => Off => Off

But now I start receiving the following error:

MongoDB\Driver\Exception\ConnectionException with message 'Could not establish stream for node APP-lb.1gnpb.mongodb.net:27017: [Failed to receive length header from server. calling hello on 'APP-lb.1gnpb.mongodb.net:27017']'

So I guess I'll be looking forward to any release you make to check if them solve my current issue.

Thank you again!

Here again to give an update about this issue:

Managed to compile version 1.21.0 and make it work. So far seems that is working as expected without the issue, just need more time & tests to be done to be sure the issue don't come up later.

Thank you

I just opened PHPC-2071 to track the upgrade to libmongoc 1.20.1. Once mongodb/mongo-php-driver#1304 is tested and merged, I'll proceed with releasing version 1.12.1 of ext-mongodb.

1.12.1 has been released.