mongodb/mongo-php-driver — pull request #735 by jmikola (2014-09-11 15:55:41+00:00)
Title: PHP-1220: Ensure topology discovery pings all known hosts

https://jira.mongodb.org/browse/PHP-1220

Previously, mongo_discovery_topology would append hosts to the servers array only after creating a new connection. This meant that hosts might get duplicate entries in the list after a failover reconnection (if they were also in the seed list). More significantly, this meant that hosts not in the seed list would be ignored if they already had a persistent connection from a previous request.

After collecting known hosts from an isMaster response, add the host to the servers array if an equivalent definition entry does not exist. This ensures hosts are not ignored, but also avoids adding a duplicate entry for reconnections, which means we will not immediately send isMaster to those hosts in a subsequent next loop iteration (this is OK, as they will be queried during the next isMaster interval).

Additionally, by not adding duplicate entries, we should avoid overflowing the servers array (until replica set size limits are raised), which is currently fixed size.