[CSHARP-869] Stop Caching the IPEndPoint for a Server Instance. Created: 05/Dec/13  Updated: 04/Feb/20  Resolved: 20/Feb/14

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.8.3
Fix Version/s: 1.9

Type: Improvement Priority: Minor - P4
Reporter: Craig Wilson Assignee: Craig Wilson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to JAVA-310 Driver reconnect does not detect netw... Closed

 Description   

Currently, we cache the IPEndPoint after we have resolved a server's hostname from DNS. In some cases, if a machine is moved to a different IP address and DNS is updated, this will prevent the driver from reconnecting to this machine.



 Comments   
Comment by Igor Silva [ 04/Feb/20 ]

It appears to have regressed in v2.7.

We have a k8s cluster containing a mongo replicaSet (1 node right now) and a group of pods connecting into it via the cluster's DNS (my-db-0.my-db). Whenever the DB pod restarts - for any reason - and it's IP is changed, the dotnet app isn't able to connect anymore.

The log we see is the following:

 

Connection id "0HLT6C0Q7AJ0H", Request id "0HLT6C0Q7AJ0H:0002FF9B": An unhandled exception was thrown by the application.
2020-02-04T15:01:43.024673163Z 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 : [{ ServerId: "{ ClusterId : 1, EndPoint : "10.240.0.19:27017" }", EndPoint: "10.240.0.19:27017", State: "Disconnected", Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException: No route to host 10.240.0.19:27017

Note: 10.240.0.19 is the old IP (pre-restart). The new one is 10.240.0.21.

I've been able to ping from one of the pods and it does correctly point to the new IP. The issue seems to be on the Mongo Layer. Restarting the application pod does solve as the cache is cleaned.

 

Comment by Githook User [ 20/Feb/14 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-869: stop caching ip addresses.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/5d7ffae4a78b6021b04e27935260e665dba6747f

Comment by Vincent [ 06/Dec/13 ]

Thanks for the precision, Craig!

Comment by Craig Wilson [ 06/Dec/13 ]

The machine is already caching this on some level, so any caching we do is redundant. In addition, we are pooling connections, so the amount of speed up is very minimal.

Comment by Vincent [ 06/Dec/13 ]

You should probably keep this cache and simply make the driver try to update it every X seconds (because this cache is nice to speed up new connections/in case of DNS failures).

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