Skip to content

Manager::selectServer(): SSL/TLS already set-up for this stream #328

@a-carvallo

Description

@a-carvallo

Hi,

I'm having in issue when connecting to a replicaSet of 3 servers with SSL and authentication with the following :

$uriOptions = [];
$uriOptions["readPreference"] = \MongoDB\Driver\ReadPreference::RP_NEAREST;
$uriOptions['ssl'] = true;
$uriOptions["replicaSet"] = "plop";
$uriOptions['username'] = "not actual username";
$uriOptions['password'] = "not actual password";

$context = stream_context_create(array(
    "ssl" => array(
        "cafile"            => "/etc/ssl/certs/SSLCertificateChainFile.crt",
        "allow_self_signed" => false,
        "verify_peer"       => false,
        "verify_expiry"     => false
    )
));
error_log("context OK");

$client = new \MongoDB\Client("mongodb://db1.myhost.com:27017,db2.myhost.com:27017,db3.myhost.com:27017", $uriOptions, ['context' => $context]);
error_log("client OK");

$db = $client->selectDatabase("myDB");
error_log("selectDB OK");

$db->command(['ping' => 1]);
error_log("ping OK");

The issue happens when calling that code twice, with a small interval between.
(If I do it 10 times in a row for example, it's going to work for tries 1,3,5,7,9 and fail for the others)

Result for 2 calls :

context OK
client OK
selectDB OK
ping OK

context OK
client OK
selectDB OK
MongoDB\Driver\Exception\SSLConnectionException: MongoDB\Driver\Manager::selectServer(): SSL/TLS already set-up for this stream in /var/www/BackEnd/vendor/mongodb/mongodb/src/Database.php:158
Stack trace:
#0 /var/www/BackEnd/vendor/mongodb/mongodb/src/Database.php(158): MongoDB\Driver\Manager->selectServer(Object(MongoDB\Driver\ReadPreference))
#1 /var/www/BackEnd/app/models/base.php(72): MongoDB\Database->command(Array)

So it happens in MongoDB\Driver\Manager::selectServer() when querying the db (command, count, find...).

Config:

Ubuntu 14.04.3 LTS
Apache/2.4.7
PHP 7.0.6-13+donate.sury.org~trusty+1
mongodb version => 1.1.6
libmongoc version => 1.3.5
libbson version => 1.3.5
mongo-php-library 1.0.2

Tell me if you need extra info and thanks by advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions