Skip to content
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

Issue with headless service connection string #101

Open
CarloAlbertoS opened this issue Apr 12, 2019 · 0 comments
Open

Issue with headless service connection string #101

CarloAlbertoS opened this issue Apr 12, 2019 · 0 comments

Comments

@CarloAlbertoS
Copy link

CarloAlbertoS commented Apr 12, 2019

Hi,
I successfully installed the replicaset, and everything works fine except when I try to connect from an application, where I randomly get this error using the headless service in the connection string:
mongodb://mongo-hlservice

2019-04-12T16:05:29.650570679Z [16:05:29 ERR] Connection id "0HLLVC1EI38R1", Request id "0HLLVC1EI38R1:00000001": An unhandled exception was thrown by the application.
2019-04-12T16:05:29.650623979Z System.TimeoutException: A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = ReadPreferenceServerSelector{ ReadPreference = { Mode : Primary } }, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "1", ConnectionMode : "Automatic", Type : "ReplicaSet", State : "Connected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/mongo-hlservice:27017" }", EndPoint: "Unspecified/mongo-hlservice:27017", State: "Connected", Type: "ReplicaSetSecondary", WireVersionRange: "[0, 7]" }] }.

While everything works as expected if I specify the pod names in the connection string:
mongodb://mongo-0.mongo-hlservice.default.svc.cluster.local:27017,mongo-1.mongo-hlservice.default.svc.cluster.local:27017,mongo-2.mongo-hlservice.default.svc.cluster.local:27017/

I suppose the issue could be related to readPreference settings, because trying to connect directly from my application pod to mongodb://mongo-hlservice I am randomly routed to primary and secondaries at each try, but the mongo driver should be able to retrieve the primary name from each node via the config, which is the following:

{
        "_id" : "mongok8s",
        "version" : 7,
        "protocolVersion" : NumberLong(1),
        "writeConcernMajorityJournalDefault" : true,
        "members" : [
                {
                        "_id" : 1,
                        "host" : "mongo-1.mongo-hlservice.default.svc.cluster.local:27017",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                },
                {
                        "_id" : 2,
                        "host" : "mongo-2.mongo-hlservice.default.svc.cluster.local:27017",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                }
,
                {
                        "_id" : 0,
                        "host" : "mongo-0.mongo-hlservice.default.svc.cluster.local:27017",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                }
        ]
}

I attached also my yaml, any clue or suggestion on why I have this error?

Thanks,
Carlo Alberto

mongo-statefulset.yaml.zip

@CarloAlbertoS CarloAlbertoS changed the title Issue with headless service connecction string Issue with headless service connection string Apr 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant