[CSHARP-738] Unable to connect to the server { }:27017 Created: 01/May/13  Updated: 20/Mar/14  Resolved: 13/Jun/13

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

Type: Bug Priority: Blocker - P1
Reporter: Harman Assignee: Craig Wilson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

I am getting this issue with latest C# driver version 1.8.1 frequently while I run even simple query on a large collection.

However this does not generate in all cases and it works sometimes but fails sometimes which is really frustrating.

The mongo server is on Amazon Ec2 ubuntu instance and .net app is on another EC2 server.

Tried Sevres fixes like connectiontimeout,sockettimeout etc but not able to fix this.

Unable to connect to the server ec2-143-39-225-37.us-west-1.compute.amazonaws.com:27017.
at MongoDB.Driver.Internal.DirectMongoServerProxy.ChooseServerInstance(ReadPreference readPreference) in c:\projects\mongo-csharp-driver\MongoDB.Driver\Communication\Proxies\DirectMongoServerProxy.cs:line 115
at MongoDB.Driver.MongoServer.AcquireConnection(ReadPreference readPreference) in c:\projects\mongo-csharp-driver\MongoDB.Driver\MongoServer.cs:line 935
at MongoDB.Driver.MongoCollection.Update(IMongoQuery query, IMongoUpdate update, MongoUpdateOptions options) in c:\projects\mongo-csharp-driver\MongoDB.Driver\MongoCollection.cs:line 1589

Please help asap.



 Comments   
Comment by Craig Wilson [ 16/May/13 ]

Harman,
Thanks. This all seems fine, so some more things I'd like to have from you. During the times when you are experiencing these errors, I'd like to have the log files from all the nodes in your replica set. You can just upload them here. They don't need to be the full logs, just the ranges a little before the errors start to a little after they stop.

Comment by Harman [ 16/May/13 ]

Hi Craig Wilson

I am using following code
Shape data = null;
MongoDatabase dbserver = null;
try
{
dbserver = ConnectionManager.GetMongoConnection();
var query = Query.EQ("ShapeID", shapeid);
data = dbserver.GetCollection<Shape>("shapes").FindOne(query);
}

GetMongoConnection method

public static MongoDatabase GetMongoConnection()

{ MongoServer mongo = new MongoClient(System.Configuration.ConfigurationManager.AppSettings["MongoServer"]).GetServer(); return mongo.GetDatabase(System.Configuration.ConfigurationManager.AppSettings["MongoDB"]); }

I am not using disconnect in my code.
Thanks...

Comment by Craig Wilson [ 16/May/13 ]

Harman,
Could you please post some code related to how you are:

  1. Creating a MongoClient
  2. Querying and Updating the database.

Most importantly, are you ever calling Disconnect() in your code? Calling Disconnect from within your code can manifest itself as errors exactly like the ones you are describing.

Thanks...

Comment by Harman [ 16/May/13 ]

Hi @Robert Stam,

I did not changed the or updated driver file.I just used C# version 1.8.1 official mongo driver from http://driver-downloads.mongodb.org/dotnet/index.html.
Stack trace 1 is the more serious and frequent problem than Stack trace2.

Comment by Robert Stam [ 08/May/13 ]

Stack trace 2 seems impossible because line 115 of DirectMongoServerProxy.cs is not a throw statement.

Are you building the driver yourself? Is it possible you have modified this file slightly so that the line numbers no longer match?

Comment by Harman [ 05/May/13 ]

Hi @Robert Stam,

yes stack trace is complete.Point 2 has same stack trace but with delete operation.

I am getting two issues mainly.Issue 1 is mainly occurring too often.

1)Server instance ec2-132-112-112-150.us-west-1.compute.amazonaws.com:27017 is no longer connected.

Stack Trace is :
System.InvalidOperationException: Server instance ec2-132-112-112-150.us-west-1.compute.amazonaws.com:27017 is no longer connected.
at MongoDB.Driver.MongoServerInstance.AcquireConnection() in c:\projects\mongo-csharp-driver\MongoDB.Driver\Communication\MongoServerInstance.cs:line 386
at MongoDB.Driver.MongoServer.AcquireConnection(MongoServerInstance serverInstance) in c:\projects\mongo-csharp-driver\MongoDB.Driver\MongoServer.cs:line 964
at MongoDB.Driver.MongoCursorEnumerator`1.GetMore() in c:\projects\mongo-csharp-driver\MongoDB.Driver\MongoCursorEnumerator.cs:line 348
at MongoDB.Driver.MongoCursorEnumerator`1.MoveNext() in c:\projects\mongo-csharp-driver\MongoDB.Driver\MongoCursorEnumerator.cs:line 251
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)

2)Unable to connect to the server ec2-143-39-225-37.us-west-1.compute.amazonaws.com:27017.

Stack Trace is:
MongoDB.Driver.MongoConnectionException: Unable to connect to the server ec2-143-39-225-37.us-west-1.compute.amazonaws.com:27017.
at MongoDB.Driver.Internal.DirectMongoServerProxy.ChooseServerInstance(ReadPreference readPreference) in c:\projects\mongo-csharp-driver\MongoDB.Driver\Communication\Proxies\DirectMongoServerProxy.cs:line 115
at MongoDB.Driver.MongoServer.AcquireConnection(ReadPreference readPreference) in c:\projects\mongo-csharp-driver\MongoDB.Driver\MongoServer.cs:line 935
at MongoDB.Driver.MongoCollection.Remove(IMongoQuery query, RemoveFlags flags, WriteConcern writeConcern) in c:\projects\mongo-csharp-driver\MongoDB.Driver\MongoCollection.cs:line 1361

Comment by Robert Stam [ 04/May/13 ]

This looks like just a regular network connectivity issue.

But I'm perplexed by your stack trace line numbers. Line 115 of DirectMongoServerProxy.cs does not throw an exception. It calls another method called Connect that isn't on your stack trace. Are you sure your stack trace is complete?

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