Re: SocketException using C# driver on azure

3,392 views
Skip to first unread message

craiggwilson

unread,
Jul 19, 2012, 7:55:51 PM7/19/12
to mongod...@googlegroups.com
I see that you are in a cursor.  How many documents are you pulling back at a time and how long does it take to iterate through them?

On Thursday, July 19, 2012 5:23:20 PM UTC-5, Keivan Beigi wrote:
We have a mongo replica set hosted on azure. every once in a while the connection to db fails and we get this error message.

is there a way to track this down and figure out what could be causing it? the error doesn't really say much beside the fact that connection failed.

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.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   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.BsonBuffer.LoadFrom(Stream stream, Int32 count)
   at MongoDB.Bson.IO.BsonBuffer.LoadFrom(Stream stream)
   at MongoDB.Driver.Internal.MongoConnection.ReceiveMessage[TDocument](BsonBinaryReaderSettings readerSettings, IBsonSerializationOptions serializationOptions)
   at MongoDB.Driver.MongoCursorEnumerator`1.GetReply(MongoConnection connection, MongoRequestMessage message)
   at MongoDB.Driver.MongoCursorEnumerator`1.GetFirst()
   at MongoDB.Driver.MongoCursorEnumerator`1.MoveNext()

Keivan Beigi

unread,
Jul 19, 2012, 10:53:43 PM7/19/12
to mongod...@googlegroups.com
It doesn't seem to be a specific call, it just fails randomly on different calls. it seems to be an intermittent connection issue.

sridhar

unread,
Jul 19, 2012, 11:37:03 PM7/19/12
to mongod...@googlegroups.com
Have you looked into this  http://blogs.msdn.com/b/avkashchauhan/archive/2011/11/12/windows-azure-load-balancer-timeout-details.aspx. According to this post, it should already be fixed. One way to test if this is your issue is to change the tcp keep alive and set it to something like 30 seconds. More information on setting the tcp keep alive can be found at  http://technet.microsoft.com/en-us/library/cc957548.aspx. Note since the keep alive is in milliseconds set it to 300,000. Do let us know if this helps.  

Keivan Beigi

unread,
Jul 19, 2012, 11:44:06 PM7/19/12
to mongod...@googlegroups.com
Should I use http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.settcpkeepalive.aspx
or http://technet.microsoft.com/en-us/library/cc957548.aspx?
> --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com
> See also the IRC channel -- freenode.net#mongodb

Keivan Beigi

unread,
Jul 22, 2012, 11:45:10 AM7/22/12
to mongod...@googlegroups.com
I tried updating the ttl on the db and app server machines, with non luck.

I also tried updating the driver's default values to these but still no help,

 MongoDefaults.MaxConnectionIdleTime = TimeSpan.FromHours(1);
 MongoDefaults.MaxConnectionLifeTime = TimeSpan.FromDays(1);
 MongoDefaults.SocketTimeout = TimeSpan.FromSeconds(30);

Keivan Beigi

unread,
Jul 23, 2012, 2:10:52 PM7/23/12
to mongod...@googlegroups.com
I think I've found the solution, 

MongoDefaults.MaxConnectionIdleTime = TimeSpan.FromMinutes(1); 

I think the issue is the driver trying to use connections that have been killed by azure for being idle. setting the idle time to 1 minutes fixes it, I'll try some other values to see how high i could take it without getting the socket exceptions.

sridhar

unread,
Jul 23, 2012, 3:14:51 PM7/23/12
to mongod...@googlegroups.com
Thanks for working through this and the post. This is definitely something I will include on our troubleshooting section for Azure.
Reply all
Reply to author
Forward
0 new messages