[CSHARP-1462] Cant connect to IPv6 Server or localhost Created: 30/Oct/15  Updated: 02/Apr/16  Resolved: 30/Oct/15

Status: Closed
Project: C# Driver
Component/s: Connectivity
Affects Version/s: 2.1
Fix Version/s: 2.0.2, 2.1.1

Type: Bug Priority: Critical - P2
Reporter: Bastian Broekmans [X] Assignee: Craig Wilson
Resolution: Done Votes: 0
Labels: regression
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows Client (ipv6), CentOS Server ipv6



 Description   

A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = ReadPreferenceServerSelector{ ReadPreference =

{ Mode = Primary, TagSets = [] }

}, LatencyLimitingServerSelector

{ AllowedLatencyRange = 00:00:00.0150000 }

}. Client view of cluster state is { ClusterId : "1", ConnectionMode : "Automatic", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId: "

{ ClusterId : 1, EndPoint : "Unspecified/::1:27017" }

", EndPoint: "Unspecified/::1:27017", State: "Disconnected", Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.ArgumentException: Keine der ermittelten oder angegebenen Adressen entspricht der Socketadressfamilie.
Parametername: context
bei System.Net.Sockets.Socket.DoMultipleAddressConnectCallback(Object result, MultipleAddressConnectAsyncResult context)
bei System.Net.Sockets.Socket.DoDnsCallback(IAsyncResult result, MultipleAddressConnectAsyncResult context)
bei System.Net.Sockets.Socket.BeginConnect(String host, Int32 port, AsyncCallback requestCallback, Object state)
bei MongoDB.Driver.Core.Connections.TcpStreamFactory.<ConnectAsync>d__4.MoveNext()
— Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde —
bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
bei System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
bei MongoDB.Driver.Core.Connections.TcpStreamFactory.<CreateStreamAsync>d__3.MoveNext()
— Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde —
bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
bei System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
bei MongoDB.Driver.Core.Connections.BinaryConnection.<OpenAsyncHelperAsync>d__44.MoveNext()
— Ende der internen Ausnahmestapelüberwachung —
bei MongoDB.Driver.Core.Connections.BinaryConnection.<OpenAsyncHelperAsync>d__44.MoveNext()
— Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde —
bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
bei System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
bei MongoDB.Driver.Core.Servers.ClusterableServer.<HeartbeatAsync>d__41.MoveNext()" }] }.

When connecting to a IPv6 Server or to ipv6 localhost ([::1]) with:

var client = new MongoClient("mongodb://[::1]:27017/?ipv6=true");
var database = client.GetDatabase("DocumentGenerator");
var collections = await database.ListCollectionsAsync(); // Times out!



 Comments   
Comment by Githook User [ 30/Oct/15 ]

Author:

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

Message: CSHARP-1462: IPv6 addresses were getting lost in the shuffle.
Branch: v2.0.x
https://github.com/mongodb/mongo-csharp-driver/commit/7da530f3f9d89e9cb71ee9cb2a253d0d1c36b6ef

Comment by Githook User [ 30/Oct/15 ]

Author:

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

Message: CSHARP-1462: IPv6 addresses were getting lost in the shuffle.
Branch: v2.1.x
https://github.com/mongodb/mongo-csharp-driver/commit/142cd7ea56fc9c241f26a35e4427d66d6af725af

Comment by Githook User [ 30/Oct/15 ]

Author:

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

Message: CSHARP-1462: IPv6 addresses were getting lost in the shuffle.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/a93fa6ea4e8d29026cb84637c103ec3e7cf4e367

Comment by Bastian Broekmans [X] [ 30/Oct/15 ]

Thank you Craig, i'm looking forward for your reply. Going to get crazy about this problem

Comment by Craig Wilson [ 30/Oct/15 ]

Hi Bastian,

Ok... I can reproduce this with 2.1. I was using our master branch which has apparently fixed this problem. I'm tracing the commit back to see where it got fixed and will look at backporting. I'll let you know.

Craig

Comment by Bastian Broekmans [X] [ 30/Oct/15 ]

Hi Craig,
the connection is not working on a local mongod with --ipv6 and either on a dedicated CentOS server. The CentOS machine running mongodb is ipv6 only.

But connecting both, local and remote server works like charm with mongo.exe from my development machine

Bastian

Comment by Bastian Broekmans [X] [ 30/Oct/15 ]

{
        "argv" : [
                "/usr/bin/mongod",
                "-f",
                "/etc/mongod.conf"
        ],
        "parsed" : {
                "config" : "/etc/mongod.conf",
                "net" : {
                        "http" : {
                                "JSONPEnabled" : true,
                                "RESTInterfaceEnabled" : true,
                                "enabled" : true
                        },
                        "ipv6" : true,
                        "port" : 27017,
                        "unixDomainSocket" : {
                                "enabled" : true
                        }
                },
                "processManagement" : {
                        "fork" : true,
                        "pidFilePath" : "/var/run/mongodb/mongod.pid"
                },
                "replication" : {
                        "replSetName" : "replica01"
                },
                "security" : {
                        "authorization" : "enabled",
                        "clusterAuthMode" : "keyFile",
                        "keyFile" : "/var/lib/mongo/.keyfile"
                },
                "setParameter" : {
                        "enableLocalhostAuthBypass" : "true"
                },
                "storage" : {
                        "dbPath" : "/var/lib/mongo/",
                        "directoryPerDB" : true,
                        "engine" : "wiredTiger",
                        "journal" : {
                                "enabled" : true
                        },
                        "wiredTiger" : {
                                "collectionConfig" : {
                                        "blockCompressor" : "snappy"
                                },
                                "engineConfig" : {
                                        "cacheSizeGB" : 100,
                                        "journalCompressor" : "snappy"
                                },
                                "indexConfig" : {
                                        "prefixCompression" : true
                                }
                        }
                },
                "systemLog" : {
                        "destination" : "file",
                        "logAppend" : true,
                        "path" : "/var/log/mongodb/mongod.log",
                        "timeStampFormat" : "iso8601-utc"
                }
        },
        "ok" : 1
}

Comment by Craig Wilson [ 30/Oct/15 ]

Hi Bastien,

I was able to reproduce what you see only when the mongod.exe is not started with that --ipv6 flag. In addition, I was still able to connect to the server from mongo.exe with the --ipv6 flag set. In both cases, the flag is simply enabling ipv6, not restricting to only ipv6. In other words, with ipv6 specified, the mongod.exe still listens on ipv4 and mongo.exe will still attempt to connect on ipv4 if necessary.

Regardless, it seems you are still seeing a problem. Could you provide the output of this command:

db.adminCommand({getCmdLineOpts:1})

Also, what do you mean on the foreign server? [::1] is localhost.

Craig

Comment by Bastian Broekmans [X] [ 30/Oct/15 ]

On the foreign server the config file includes:

net:
ipv6: true
port: 27017
unixDomainSocket:
enabled: true

Tthe connection to the foreign server via mongo.exe could be accomplished but not via the c# Driver.

Bastian

Comment by Bastian Broekmans [X] [ 30/Oct/15 ]

Hi Craig, yes the server is started with --ipv6. Connecting via mongo.exe is working like charm.

Bastian

Comment by Craig Wilson [ 30/Oct/15 ]

Hi Bastian, I've just tested this and was able to connect to [::1] on my computer. You must also tell the server to listen on an ipv6 port by using the -ipv6 switch when starting mongod.exe.

Could you please confirm ipv6 is turned on at the server?
Craig

Comment by Bastian Broekmans [X] [ 30/Oct/15 ]

Connecting via mongo.exe is possible with the --ipv6 parameter!

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