Actually, the exception message just says “Socket exception”, but I went into the source code and saw “Couldn’t connect to 127.0.0.1” message. Any suggestions?
To clarify: I have roughly 10 to 20 connections being made per second every second, and exceptions are being thrown like twice per minute on average with unpredictable intervals and density. I fail to see any pattern.
P. S. I’m getting this exception both on Windows and Linux. GDB and QtCreator suck on Linux, however, so I only investigated it on Windows.
10 to 20 connections being made per second every second, you say?
You are almost certainly overflowing the “listen backlog” on the server. When a POSIX server program wants to listen for incoming socket connections, it calls
listen()with abacklogargument, which is often roughly 5-100 or so. This sets the maximum number of incoming connections that the operating system will allow to be pending at the same time. So you can have more than 100 connections, but you cannot have 100 (or maybe even 10) in flight at once on the server. You can read about this here: http://www.linuxjournal.com/files/linuxjournal.com/linuxjournal/articles/023/2333/2333s2.htmlAnd indeed from the MongoDB bug tracker it appears that they use a default of 5. See here: https://jira.mongodb.org/browse/SERVER-2554 . On the other hand, the actual code on GitHub shows a backlog argument of 128: https://github.com/mongodb/mongo/blob/5a2f4ceb93b44283500f1ed346898439ca33b137/util/net/listen.cpp#L138 , and I went back 2.5 years and it seems like it had it as 128 then too. I’m not sure this is true, though–if it is, the Mongo people are not keeping their bug list up to date.