[CSHARP-2037] Cannot connect to local server using hostname 'localhost', only IP '127.0.0.1' Created: 09/Sep/17  Updated: 27/Oct/23  Resolved: 13/Oct/17

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

Type: Bug Priority: Minor - P4
Reporter: Alexander Regueiro Assignee: Robert Stam
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

FreeBSD 11.1, Mono 5.2, MongoDB 3.4.4



 Description   

I have a default configuration of MongoDB 3.4.4 (installed from pkg) on FreeBSD. I can connect fine with the CLI (using 'localhost' or '127.0.0.1') or from my .NET/C# program (only using the IP 127.0.0.1), but connecting using 'localhost' from within my program is timing out with the following error:

System.TimeoutException:  A timeout occured after 10000ms selecting a server using CompositeServerSelector{
     Selectors = WritableServerSelector,
     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/localhost: 27017\" 
            }\",
             EndPoint:  \"Unspecified/localhost: 27017\",
             State:  \"Disconnected\",
             Type:  \"Unknown\" 
        }
    ] 
}.\n  at MongoDB.Driver.Core.Clusters.Cluster.ThrowTimeoutException (MongoDB.Driver.Core.Clusters.ServerSelectors.IServerSelector selector,
 MongoDB.Driver.Core.Clusters.ClusterDescription description) [
    0x00013
] in <295d3f442b614d5d817f23ef80ed36dc>: 0 \n  at MongoDB.Driver.Core.Clusters.Cluster+WaitForDescriptionChangedHelper.HandleCompletedTask (System.Threading.Tasks.Task completedTask) [
    0x00009
] in <295d3f442b614d5d817f23ef80ed36dc>: 0 \n  at MongoDB.Driver.Core.Clusters.Cluster.WaitForDescriptionChanged (MongoDB.Driver.Core.Clusters.ServerSelectors.IServerSelector selector,
 MongoDB.Driver.Core.Clusters.ClusterDescription description,
 System.Threading.Tasks.Task descriptionChangedTask,
 System.TimeSpan timeout,
 System.Threading.CancellationToken cancellationToken) [
    0x00021
] in <295d3f442b614d5d817f23ef80ed36dc>: 0 \n  at MongoDB.Driver.Core.Clusters.Cluster.SelectServer (MongoDB.Driver.Core.Clusters.ServerSelectors.IServerSelector selector,
 System.Threading.CancellationToken cancellationToken) [
    0x00057
] in <295d3f442b614d5d817f23ef80ed36dc>: 0 \n  at MongoDB.Driver.Core.Bindings.WritableServerBinding.GetWriteChannelSource (System.Threading.CancellationToken cancellationToken) [
    0x00011
] in <295d3f442b614d5d817f23ef80ed36dc>: 0 \n  at MongoDB.Driver.Core.Operations.BulkMixedWriteOperation.Execute (MongoDB.Driver.Core.Bindings.IWriteBinding binding,
 System.Threading.CancellationToken cancellationToken) [
    0x00006
] in <295d3f442b614d5d817f23ef80ed36dc>: 0 \n  at MongoDB.Driver.OperationExecutor.ExecuteWriteOperation[
    TResult
] (MongoDB.Driver.Core.Bindings.IWriteBinding binding,
 MongoDB.Driver.Core.Operations.IWriteOperation`1[
    TResult
] operation,
 System.Threading.CancellationToken cancellationToken) [
    0x00000
] in : 0 \n  at MongoDB.Driver.MongoCollectionImpl`1[
    TDocument
].ExecuteWriteOperation[
    TResult
] (MongoDB.Driver.Core.Operations.IWriteOperation`1[
    TResult
] operation,
 System.Threading.CancellationToken cancellationToken) [
    0x0000c
] in : 0 \n  at MongoDB.Driver.MongoCollectionImpl`1[
    TDocument
].BulkWrite (System.Collections.Generic.IEnumerable`1[
    T
] requests,
 MongoDB.Driver.BulkWriteOptions options,
 System.Threading.CancellationToken cancellationToken) [
    0x00039
] in : 0 \n  at MongoDB.Driver.MongoCollectionBase`1[
    TDocument
].InsertOne (TDocument document,
 MongoDB.Driver.InsertOneOptions options,
 System.Threading.CancellationToken cancellationToken) [
    0x00030
] in : 0 \n  at Iinu.Server.Database.DatabaseClient.AddKitchen (Iinu.Server.Database.Kitchen kitchen) [
    0x00007
] in <47651e00c1fc448c853303d65a8c12a6>: 0 \n  at Iinu.Server.Registration.KitchenRegistrationService.Register (Iinu.Server.Api.Data.Kitchen kitchen,
 MongoDB.Bson.ObjectId& kitchenId) [
    0x00020
] in <47651e00c1fc448c853303d65a8c12a6>: 0 \n  at Iinu.Server.Api.IdentityModule.b__2_2 (System.Object parameters) [
    0x00008
] in <47651e00c1fc448c853303d65a8c12a6>: 0 \n  at (wrapper dynamic-method) System.Object: CallSite.Target (System.Runtime.CompilerServices.Closure,
System.Runtime.CompilerServices.CallSite,
System.Func`2,
object)\n  at System.Dynamic.UpdateDelegates.UpdateAndExecute2[
    T0,
    T1,
    TRet
] (System.Runtime.CompilerServices.CallSite site,
 T0 arg0,
 T1 arg1) [
    0x0010f
] in : 0 \n  at Nancy.Routing.Route+<>c__DisplayClass4.b__3 (System.Object parameters,
 System.Threading.CancellationToken context) [
    0x00049
] in : 0

This distinctly seems like a bug to me, either in MongoDB or Mono.



 Comments   
Comment by Robert Stam [ 13/Oct/17 ]

Works as designed except on Mono.

Comment by Robert Stam [ 21/Sep/17 ]

We currently don't officially support the .NET driver on Mono.

We are willing to make changes submitted by contributors to work around Mono limitations, but we don't officially test against or support running on Mono.

I have verified that this issue does not occur on Windows.

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