Sometimes we get this error message when trying to get a specific document:
System.IO.IOException: Unable to read data from the transport connection:
A connection attempt failed because the connected party did not properly
respond after a period of time, or established connection failed because
connected host has failed to respond.
---> System.Net.Sockets.SocketException: A connection attempt failed because the
connected party did not properly respond after a period of time, or established
connection failed because connected host has failed to respond
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at MongoDB.Bson.IO.ByteBufferFactory.LoadFrom(Stream stream)
at MongoDB.Driver.Internal.MongoConnection.ReceiveMessage[TDocument] (BsonBinaryReaderSettings readerSettings, IBsonSerializer serializer, IBsonSerializationOptions serializationOptions)
at MongoDB.Driver.Operations.QueryOperation`1.GetFirstBatch(IConnectionProvider connectionProvider)
at MongoDB.Driver.Operations.QueryOperation`1.Execute(IConnectionProvider connectionProvider)
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
at ... Linq statement in our code
It seems like it happens to document that are saved just recently.
If I run the query to get this document in MongoDB shell from web server it just hangs. Getting all documents including this document runs fine.
If I run the same query from another machine, everything is fine.
The only way to fix this is to change one property on this specific document from another machine.
Enviroment:
- MongoDB v2.6.3 on Windows Server 2012.
- C# / asp.net on Windows Server 2008 R2
- mongocsharpdriver version 1.9.2.
Process Monitor Screen Dump on web server running query in Mongo Shell:
Sample document/json that hangs from one server
{
"_id": "a635399137391923437",
"Title": "Confectionery & Snacks",
"NavigationAreas": {
"Items": {
"TopMenu": {
"_id": "TopMenu",
"Items": [
{
"Title": "C. Library",
"Url": "/ActivityOwnerDashboard/Index?activityOwnerDashboardId=a634395044701382271&activityownerId={activityownerId\n}&language={language}",
"Enable": true,
"IsPublic": true,
"VisibleToRoles": [
"Members",
"Editor",
"Administrators",
"Agency1",
"Agency2",
"Corporatemembers"
]
},
{
"Title": "T. Monitors",
"Url": "/Dashboard/Index?dashboardId=a635073303205437766&activityownerId={activityownerId}&language={langu\nage}",
"Enable": true,
"IsPublic": true,
"VisibleToRoles": [
"Members",
"Editor",
"Administrators",
"Agency1",
"Agency2",
"Corporatemembers"
]
},
{
"Title": "Administration",
"Url": "/ActivityOwnerDashboard/Index?activityOwnerDashboardId=a634988042201870012&activityownerId={activityownerId}&language={\nlanguage}",
"Enable": true,
"IsPublic": true,
"VisibleToRoles": [
"Editor",
"Administrators",
"Agency1",
"Agency2"
]
},
{
"Title": "KPI Monitors",
"Url": "/Dashboard/Index?dashboardId=a635288464367511308&activityownerId={activityOwnerId}&language={language}",
"Enable": true,
"IsPublic": true,
"VisibleToRoles": [
"Members",
"Editor",
"Administrators",
"Agency1",
"Agency2",
"Corporatemembers"
]
}
]
}
}
},
"Timestamp": NumberLong("6354421106745")
}