mongodb-csharp


MongoDB C# 2.0 TimeoutException


We've recently upgraded our web application to MongoDB C# Driver 2.0 and deployed to production. Below a certain load, the application runs fine. Once the load on the production server exceeds a certain limit, the CPU of the application instantly falls down to 0 and after about 30 seconds, this exception is logged several times:
System.TimeoutException message: A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = ReadPreferenceServerSelector{ ReadPreference = { Mode = Primary, TagSets = System.Collections.Generic.List`1[MongoDB.Driver.TagSet] } }, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "1", Type : "Standalone", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/10.4.0.113:27017" }", EndPoint: "Unspecified/10.4.0.113:27017", State: "Disconnected", Type: "Unknown" }] }.
stack trace:
at MongoDB.Driver.Core.Clusters.Cluster.ThrowTimeoutException(IServerSelector selector, ClusterDescription description)
at MongoDB.Driver.Core.Clusters.Cluster.<WaitForDescriptionChangedAsync>d__18.MoveNext()
--- End of stack trace
We are using a singleton MongoClient object, which is initiated like this:
private static object _syncRoot = new object();
private static MongoClient _client;
private static IMongoDatabase _database;
private IMongoDatabase GetDatabase()
{
...
if (_client == null)
{
lock (_syncRoot)
{
if (_client == null)
{
_client = new MongoClient(
new MongoClientSettings
{
Server = new MongoServerAddress(host, port),
Credentials = new[] { credentials },
});
_database = _client.GetDatabase("proddb");
return _database;
}
}
}
return _database;
}
public IMongoCollection<T> GetCollection<T>(string name)
{
return GetDatabase().GetCollection<T>(name);
}
A typical call to database looks like this:
public async Task<MongoItem> GetById(string id)
{
var collection = _connectionManager.GetCollection<MongoItem>("items");
var fdb = new FilterDefinitionBuilder<MongoItem>();
var f = fdb.Eq(mi => mi.Id, id);
return await collection.Find(f).FirstOrDefaultAsync();
}
How can we discover the reason and fix this issue?
https://groups.google.com/forum/#!topic/mongodb-csharp/O460OHiFjZs
this may help
quota:
I figured it out. This JIRA ticket has the details: https://jira.mongodb.org/browse/CSHARP-1160
Effectively, we've made a distinction between connecting to a standalone server and connecting directly to a replica set member, where the latter is relatively uncommon. Unfortunately, MongoLab's Single-Node settings are actually a single node replica set and this causes us to not trust it. You can fix this by appending ?connect=replicaSet to your connection string. It will force the driver to move into replica set mode and all will work.
We are going to re-consider CSHARP-1160 in light of this. Thanks so much for reporting and let me know if appending ?connect=replicaSet to your connection string doesn't work.
I had this same problem when I was using the free (version 2.6) sandbox in MongoLab and the timeout issue went away when I started using a paid-for cluster.
I was going to say that I thought the issue was that only MongoDB version 3.0+ is supported (because I found some docs saying as much, and I swear I went through the 3.0 upgrade process via MongoLab), but when I went to search for the documentation, it now says 2.6 is supported and my paid MongoLab DB still says it's version 2.6.9.
I think I must be going crazy, but at least my code is working now!
I was experiencing the same issue using driver v2.2.4. After upgrading to v2.3.0, the issue seems to have been resolved

Related Links

Include/Exclude fields in query with MongoDB C# driver 2.4
Map old field name and new field name from mongodb document to the same c# field
foreach item in an array find largest record using mongodbcsharp driver
Is there Document Validator available for MongoDB using C# driver?
MongoDB projection on missing field on Document
MongoDB faceted search
Mongodb c# InsertOne() - How to Handle exception
How to force serialization of decimal values inside dictionaries as doubles in mongodb csharp driver?
How do I use in $in operator using the 2.0 version of the C# mongodb driver?
What is the purpose of the MaxConnectionLifeTime setting
MongoDB C# driver throws timeout exception when trying to connect to replica set
Serialize Dictionary<long, VALUE> to BSON documents
Using a Regex against a simple list with `ElemMatch` in MongoDB .NET
projection wont work in mongodb c# driver
BsonClassMapSerializer already registered for AbstractClassSerializer
MongoDb C# Driver 2.0 Coalesce (or equivalent)?

Categories

HOME
deep-learning
android-studio-2.2
twig
zend-framework
toolbox
obfuscation
oracle-apex-5
solaris
owl-carousel
grafana
nuget-package
frontend
vert.x
flume
modal-dialog
owin
octave
gson
alamofire
line
intercom
do-while
scsi
null-pointer
firefox-addon
boost-icl
topology
selinux
backpack-for-laravel
angular-routing
qliksense
interpreter
strongname
onload
itunes
android-maps
datastax-enterprise-graph
openmdao
winpe
custom-controls
cart
playstation-portable
r-grid
contacts
nested-lists
engine.io
swagger-php
openerp-7
jpad
graphhopper
recurrent-neural-network
railstutorial.org
cin
skylink
dcmtk
naming
ssrs-2014
apollostack
drupal-theming
boo
bbpress
reshape
rxtx
renaming
smartfoxserver
stripe-connect
lrs
signalr.client
gogs
kiosk
thread-sleep
inf
iokit
microsoft-reporting
include-guards
finalbuilder
dulwich
pyobjc
keyup
ms-access-2000
dot.js
public-html
ssis-data-flow
rickshaw
build-script
rcaller
jjaql
ios8-extension
authlogic
menubar
square-bracket
visual-studio-express
solace-mq
mysql-error-1044
windows-phone-8-sdk
mongohq
ui-select2
pagedown
extconf.rb
appjs
infobright
fsevents
update-statement
appledoc
uideviceorientation
delimited-text
updatesourcetrigger
ajax-polling
perl5.12
soappy
wcf-proxy
leader

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App