[CSHARP-2888] Split-Horizon connection issue from outside Kubernetes Created: 26/Dec/19  Updated: 15/Jan/20  Resolved: 15/Jan/20

Status: Closed
Project: C# Driver
Component/s: Connectivity
Affects Version/s: 2.10.0
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Andrii Litvinov Assignee: Dmitry Lukyanov (Inactive)
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Kubernetes, external replica set connectivity. ,NET Core



 Description   

I have a ReplicaSet deployed with MongoDB Operator to Kubernetes and configured with Split-Horizon as follows:

security:
  tls:
    enabled: true
  authentication:
    enabled: true
    modes: ["SCRAM"]
 
connectivity:
  replicaSetHorizons:
    - "horizon-1": "node-2:31502"

I can connect to it from shell in a following connection way:

mongo mongodb://admin:admin-password@node-2:31502/admin?replicaSet=mongo-local-0 --tls --tlsAllowInvalidCertificates

From C# I am trying following:

var settings = MongoClientSettings.FromConnectionString("mongodb://admin:admin-password@node-2:31502/admin");
settings.UseTls = true;
settings.AllowInsecureTls = true;
settings.ReplicaSetName = "mongo-local-0";
 
var cursor = await new MongoClient(settings).ListDatabasesAsync();
await cursor.MoveNextAsync();
 
cursor.Current.Should().NotBeEmpty();

But it fails with connection timeout exception:

System.TimeoutException : A timeout occured after 30000ms selecting a server using CompositeServerSelector\{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is \{ ClusterId : "1", ConnectionMode : "ReplicaSet", Type : "ReplicaSet", State : "Disconnected", Servers : [] }.
 at MongoDB.Driver.Core.Clusters.Cluster.ThrowTimeoutException(IServerSelector selector, ClusterDescription description)
 at MongoDB.Driver.Core.Clusters.Cluster.WaitForDescriptionChangedHelper.HandleCompletedTask(Task completedTask)
 at MongoDB.Driver.Core.Clusters.Cluster.WaitForDescriptionChangedAsync(IServerSelector selector, ClusterDescription description, Task descriptionChangedTask, TimeSpan timeout, CancellationToken cancellationToken)
 at MongoDB.Driver.Core.Clusters.Cluster.SelectServerAsync(IServerSelector selector, CancellationToken cancellationToken)
 at MongoDB.Driver.MongoClient.AreSessionsSupportedAfterSeverSelctionAsync(CancellationToken cancellationToken)
 at MongoDB.Driver.MongoClient.AreSessionsSupportedAsync(CancellationToken cancellationToken)
 at MongoDB.Driver.MongoClient.StartImplicitSessionAsync(CancellationToken cancellationToken)
 at MongoDB.Driver.MongoClient.UsingImplicitSessionAsync[TResult](Func`2 funcAsync, CancellationToken cancellationToken)

If I comment-out replica set line connection works, but then I am not connected to a replica set, but to a single node.

Am I missing something or is it not yet supported? Is there a workaround?

 



 Comments   
Comment by Dmitry Lukyanov (Inactive) [ 15/Jan/20 ]

This issue will be fixed in SERVER-45396

Comment by Andrii Litvinov [ 27/Dec/19 ]

I used this example https://github.com/mongodb/mongodb-enterprise-kubernetes/blob/master/samples/mongodb/external-connectivity/replica-set-external.yaml and is seems to be correct. Mongo shell works as expected with it.

Comment by Andrey Belik (Inactive) [ 27/Dec/19 ]

This option configures Server Split Horizon feature to return different names for isMaster driver calls.

ben.elgar Does this K8S config looks correct?

 

Comment by Andrii Litvinov [ 27/Dec/19 ]

Thank you for a reply, Andrew. When I run it with mongo shell I do see that server return hostnames from that horizon. I use MongoDB 4.2.2. As I wrote in the issue, it works perfectly well in mongo shell. Do you know why it might not be working with C# driver?

From this I conclude that driver cannot recognize servers returned by mongodb:

{ ClusterId : "1", ConnectionMode : "ReplicaSet", Type : "ReplicaSet", State : "Disconnected", Servers : [] }

Comment by Andrew Davidson [ 27/Dec/19 ]

This should not be a driver-relavent feature. It's server side--when a connection comes in using hostnames from a certain horizon, the server returns the hostnames from the replica set in that horizon.

Generated at Wed Feb 07 21:43:47 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.