-
Notifications
You must be signed in to change notification settings - Fork 264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Impossible to connect to a single member replica set through PHP library #1557
Comments
I just tested one of the example scripts with a single-member replica set and was able to connect to it without an issue. Since you mentioned this is in docker, would you be able to share the setup you were using so we can try to reproduce it? |
Hello @alcaeus, And thank you for taking a look ! Here is the Dockerfile of the built image :
the file initiateReplSet.js contains only one instruction The container is served in a Docker Compose stack, with this service definition :
The connection string configured in my local web app And the ConnectionTimeoutError on read action, through Symfony with Doctrine Mongo ODM : with the head of stack trace
|
I know you mentioned the "rs_dev" is used as the replica set name, but given the behavior you reported I expect the correct name is not actually being passed to the driver. You can also test this locally using SDAM logging and tweaking the connection string. Below are two snippets of running examples/sdam_logger.php on a local single-member replica set (named "rs0") with and without the correct Correct
|
Hello @jmikola and sorry for late response, I missed your response notification. I tested the sdam_logger.php, trying to connect to my docker MongoDB container set with replica set named Without specifying replicaSet name in the connection string
And by specifying the replicaSet name in the connection string :
I get the same issue. I looks like, the Driver get a response from the hello handshake that tells "primary is not mongo:27017" (the mapped service name in the Docker compose config), primary is located at 127.0.0.1:27017 (Docker compose config does not know this IP mapping). What do you think ? |
The error seems to be caused by disagreement between host names used in the connection string and those in the replica set configuration (which is used in You should be able to resolve this with additional hostname definitions on the driver side, which will allow the connection string to use the same hostnames found in the RS configuration. https://stackoverflow.com/a/68674898 outlines one approach for doing so. Note: the reason your first example ("Without specifying replicaSet name") succeeds is because the driver establishes a direct connection to the replica set member by virtue of the seed list including only one host and there being no |
Bug Report
I'm using a single member replica set MongoDB cluster in my development environment (and also in production in some cases), but replica set is well configured. With mongosh, I can connect to the single member by spefying the
replicaSet
URI parameter and it works well.Using PHP driver, if I set a replicaSet option, I get an error
No suitable servers found (
serverSelectionTryOnceset): [connection refused calling hello on '127.0.0.1:27017']. Topology type: ReplicaSetNoPrimary
. But through mongosh, I can check that my single member is obviously seen as PRIMARY :Environment
I'm not using TLS in dev environment, MongoDB is a Docker container (version 7.0) configured with configured
rs_dev
ReplicaSet.Library mongodb/mongodb is 1.19.1
PHP is 8.1
PHP extension is 1.20.1
It seems to be handled the same way by NodeJS driver (same issue described here : https://stackoverflow.com/questions/69531947/replicasetnoprimary-error-although-primary-exists).
Please tell me if this is expected behavior, although mongosh seems OK with single member replica set ?
The text was updated successfully, but these errors were encountered: