php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60508 When replicaSet is set, Mongo->connected is always TRUE
Submitted: 2011-12-13 03:26 UTC Modified: 2012-11-29 17:42 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: xqpmjh at gmail dot com Assigned: derick (profile)
Status: Closed Package: mongo (PECL)
PHP Version: 5.3.8 OS: winxp
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: xqpmjh at gmail dot com
New email:
PHP Version: OS:

 

 [2011-12-13 03:26 UTC] xqpmjh at gmail dot com
Description:
------------
I am not sure if this is a bug, bug it's just very strange thing.

The problem is :
when I try to setup my replica set on my local pc. Trying connect to mongo with 
the "replicaSet" option before actually 
launch any instance of mongo:

$mo = new 
Mongo('mongodb://kim:kim@localhost:27018,localhost:27019,localhost:27020/test');
var_dump($mo->connected); // it output TRUE... which is unacceptable :p

But in fact the connection had not been established, because I didn't really 
launch any mongo process.
The exception "couldn't get a connection to any server" will still be thrown, 
yes, but only until I do some queries like :

$entities = $myCollection->find();
try {
    while ($entities->hasNext()) {
        $row = $entities->getNext();
        $result[] = $row;
    }
} catch (exception $e) {
    echo 'exception thrown here...';
}

The mainly uncomfortable thing of this is that, the exception is unable to 
capture, and don't know when it will be thrown. 
Especially when trying to check connection status at the very beginning before 
doing any other things.

But if I remove the "replicaSet" option and try to connect again, this time, the 
exception will be thrown immediately, but 
with a message of "Unknown error", which is, just can't tell anything about what 
happen...


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-12-16 19:02 UTC] kristina@php.net
This is intentional, although I can see it being annoying behavior.  As long as all the addresses resolve and all of the other trivial stuff goes okay (you don't run out of memory or something), Mongo::__construct() will set connected to true.

I could see making connected=false if it can't reach anyone, but should it be true if you can only reach secondaries?  If you can only reach an arbiter?  I can't think of a way of making connected=boolean make sense in the context of replica sets.

If you want to catch this early, you could do $db->command(array("ping"=>1)) or something after connecting.
 [2011-12-19 03:22 UTC] xqpmjh at gmail dot com
Yes, $db->command(array("ping"=>1)) is a proper way of checking the connection. 
But I still think that there could be a better solution.

If we looking at the word "connected", which usually means we can "talk" to each other, then connected=true means you can both read/write to the server.
Does it mean that you are able to connect to a "primary"?

I am thinking that even some thrown exceptions are better then just a true/false when, if someone can only read, or only see the arbiter, but unable to write...

Just the modest proposal, happy PHP :)
 [2012-11-29 17:42 UTC] derick@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: derick
 [2012-11-29 17:42 UTC] derick@php.net
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at 
http://www.php.net/downloads.php

This should be fixed in the 1.3.0 release. If you continue finding problems with this, please file an issue in JIRA: http://jira.mongodb.org/browse/PHP
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 01:01:28 2024 UTC