[CSHARP-1302] MongoClient Connection issues. Created: 08/Jun/15 Updated: 05/Apr/19 Resolved: 08/Jun/15 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Paul Reed | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | question | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
I have an issue with connections failing in a certain scenario: Architecture: website#1 with primary#1 Settings: new MongoClientSettings { ReplicaSetName = "rs", Servers = < 3 server names >, ConnectionMode = ConnectionMode.ReplicaSet, ConnectTimeout = new TimeSpan(0,0,60), ReadPreference = (slaveOk) ? ReadPreference.Nearest : ReadPreference.Primary, WriteConcern = WriteConcern.Acknowledged, }– ") and generally receive a correct response with myState either being 1 or 2. – However, sometimes whilst these sites are running I will take offline secondary#2 - and run up a local non-rs instance on port 37017. When I do that, website#2 begins to respond with: A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = WritableServerSelector, LatencyLimitingServerSelector { AllowedLatencyRange = 00:00:00.0150000 }}. Client view of cluster state is { ClusterId : "1", Type : "ReplicaSet", State : "Disconnected", Servers : [{ ServerId: " { ClusterId : 1, EndPoint : "Unspecified/127.0.0.1:27017" }", .... Now - I would have expected the website to fall over to retrieve secondary#3 - but its not doing that. Am I doing something wrong? Hope you can help. |
| Comments |
| Comment by Craig Wilson [ 08/Jun/15 ] |
|
In most cases, it won't matter because if the settings are the same, we'll use the same cluster underneath. However, this isn't always true because there are certain types of settings we cannot compare. To be safe, it is always best practice to use a single MongoClient for your application. Stick it in your IoC container or something. Since we've figured this out, I'm going to go ahead and close this ticket. |
| Comment by Paul Reed [ 08/Jun/15 ] |
|
Oh Golly, Thank you: #if !DEBUG ... if (useLocal) { servers.Add(new MongoServerAddress("127.0.0.1", port)); }Cannot believe that this has been added in at some stage - it used to be #if DEBUG.. - and of course the port is coming in at the correct value. So amazingly every thing works out normally. – #redface === So, just one last thing. When using MongoClient/MongoServer within a WebSite ( utilising ApplicationPooling ) - should we be using a single MongoClient/Server per app pool instance ? |
| Comment by Craig Wilson [ 08/Jun/15 ] |
|
Right. Are you giving it 127.0.0.1 anywhere in your code? For some reason, we aren't connecting to a replica set here, just the local mongod. I've attempted to replicate this and am not having any luck. Somehow, the 3 servers you are indicating in your MongoClientSettings are not getting used. Is there anyway you could provide a reproduction of this with actual code so that I can debug through it? Craig |
| Comment by Paul Reed [ 08/Jun/15 ] |
|
If it is trying to connect to the Primary, then I really am not sure why it is using: 127.0.0.1:27017 as this is the local address to the secondary. Non of the server addresses are in IP format. |
| Comment by Paul Reed [ 08/Jun/15 ] |
|
re: 1) re: 2) A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = WritableServerSelector, LatencyLimitingServerSelector { AllowedLatencyRange = 00:00:00.0150000 }}. Client view of cluster state is { ClusterId : "1", Type : "ReplicaSet", State : "Disconnected", Servers : [{ ServerId: " { ClusterId : 1, EndPoint : "Unspecified/127.0.0.1:27017" }", EndPoint: "Unspecified/127.0.0.1:27017", State: "Disconnected", Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:27017 re: 3) The primary is up at all times, |
| Comment by Craig Wilson [ 08/Jun/15 ] |
|
Hi Paul, Sorry you are having issues. Couple of questions: 1. I don't completely understand what you've said about your architecture. Are you running your mongod instances on the same servers as your website servers? Craig |
| Comment by Paul Reed [ 08/Jun/15 ] |
|
FYI
|