[CSHARP-255] SocketException on MongoServer.Connect() Created: 24/Jun/11 Updated: 02/Apr/15 Resolved: 04/Jul/11 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | 1.1 |
| Fix Version/s: | 1.1, 1.2 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | John Woakes | Assignee: | Robert Stam |
| Resolution: | Done | Votes: | 0 |
| Labels: | connection | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Running on Azure connecting to a local VM running 3 mongod.exe as replica sets |
||
| Description |
|
This mongo url fails with the 1.1 c# driver and works with the 1.0 driver mongodb://xxxx:40000,xxxx:40001,xxxx:40002/?ipv6=true;replicaSet=xq;safe=true System.Net.Sockets.SocketException: No connection could be made This is the code... static MongoDatabase GetMongoDB(string connection) , try { var mongo = MongoServer.Create(url.ToMongoUrl()); mongo.Connect(); return mongo.GetDatabase("xq"); } catch (Exception ex) >> {1}", I put a test in to see if the Host value resolves to an IP and it does (IPv6). |
| Comments |
| Comment by John Woakes [ 05/Jul/11 ] |
|
In my case IPv6 is the only option. I had ipv6=true and used ipv6 addresses everywhere and it didn't work. But I am actually happier using machine names as they are less likely to change. |
| Comment by Robert Stam [ 05/Jul/11 ] |
|
I think you will have to be consistent and use either IPv4 or IPv6 addresses throughout. And your driver connection string should have ipv6=true if you are using IPv6 addresses. |
| Comment by John Woakes [ 04/Jul/11 ] |
|
I guess the question is should it work with IP addresses? I only tested IPv6 but I wonder if a regular IP address would work... |
| Comment by Robert Stam [ 04/Jul/11 ] |
|
Thanks for letting us know, and I'm glad it's working for you now. |
| Comment by John Woakes [ 04/Jul/11 ] |
|
It is fully working now. When initializing the replica sets you have to use host names, not localhost or IPv6 addresses. |
| Comment by John Woakes [ 28/Jun/11 ] |
|
I think I know what is happening here. When I set up the test server running mongod I set up 3 instances on the same machine and configured replication using localhost:port. If I look at rs.status() I see the names in members are localhost:port. I think the driver picks these up and tries to use them. I am in the process of trying to fix this or start afresh. I will let you know how I get on. |
| Comment by John Woakes [ 27/Jun/11 ] |
|
I added a call to this just before the failing connect private static void OutputServerDetails(MongoServer mongo) {1} ", address.Host, address.Port); catch (Exception ex) { result += ex.Message; } result += "; "; and got System.Exception: IQ-xxxxx002.iQmetrixHO.local 40000 [2a01:111:f102:122:cc28:398f:262c:3333]:40000; IQ-xxxxx002.iQmetrixHO.local 40001 [2a01:111:f102:122:cc28:398f:262c:3333]:40001; IQ-xxxxx002.iQmetrixHO.local 40002 [2a01:111:f102:122:cc28:398f:262c:3333]:40002; so it looks like the host name resolves... |
| Comment by John Woakes [ 27/Jun/11 ] |
|
I had it working with v1.0... We are running the client in Microsoft's Azure cloud platform and the mongod is running in our local data center. I will continue digging to see if I can provide more information. |
| Comment by Robert Stam [ 27/Jun/11 ] |
|
Odd then that the error message had "[::1]:40000" as the address... If the client and server are in different data centers, could it be a firewall issue? |
| Comment by John Woakes [ 27/Jun/11 ] |
|
I am not running the client and mongod on the same machine. The xxxx machine is in a different data center. Using localhost would not work. If I do a System.Net.Dns.GetHostAddresses("xxxx") from the client I get one valid IPv6 address (not localhost). I am running my mongod with the --ipv6 flag. |
| Comment by Robert Stam [ 24/Jun/11 ] |
|
I also get the same results with either the 1.0 or the 1.1 version of the driver. |
| Comment by Robert Stam [ 24/Jun/11 ] |
|
FYI, I set up a 3 member replica set and was able to connect to it using essentially the same connection string as yours: var server = MongoServer.Create("mongodb://localhost:10001,localhost:10002,localhost:10003/?safe=true;replicaset=myset;ipv6=true"); Again, I could only connect if I had used --ipv6 when starting mongod. |
| Comment by Robert Stam [ 24/Jun/11 ] |
|
Not that it necessarily explains your exception, but when I launch mongod without -ipv6 and then put "ipv6=true" in the client connection string I do get the same exception you are reporting. |
| Comment by Robert Stam [ 24/Jun/11 ] |
|
The IPv6 address [::1] is localhost, so I'm assuming that even though you are using the host name "xxxx" your client and mongod servers are all running on the same box. A connection refused exception implies that the host name was resolved correctly, but that there was no server listening on that host/port combination. Did you launch mongod with the --ipv6 command line parameter? mongod won't listen on IPv6 addresses unless you ask it to. |