title: MongoDB+Azure+Android: Error: com.mongodb.MongoException: not talking to master and retries used up
body: <p><strong>Background</strong>:</p>
  
  <p>I have MongoDB replica sets running in Azure cloud service worker + web roles, using <a href="https://github.com/mongodb/mongo-azure" rel="nofollow noreferrer">mongo-azure library</a>. The first time I setup my Android project to connect to MongoDB/Azure, IO (reads and writes) worked. Then, I crashed the app because of a typo in my hardcoded test JSONString, so the Mongo instance wasn't able to properly close. After fixing that JSONString problem, I received the following error (in stack trace) and wasn't able to access MongoDB/Azure. Perhaps not closing the connection properly caused the error?</p>
  
  <p><strong>Question</strong>: </p>
  
  <p>What exactly does this error mean? Why wouldn't the master instance be available?</p>
  
  <pre><code>E/AndroidRuntime: com.mongodb.MongoException: not talking to master and retries used up
  </code></pre>
  
  <p><strong>Full stack trace</strong>: </p>
  
  <pre><code>E/AndroidRuntime(6274): FATAL EXCEPTION: Thread-7108
  E/AndroidRuntime(6274): Process: com.myproject.examplemongodb, PID: 6274
  E/AndroidRuntime(6274): com.mongodb.MongoException: not talking to master and retries used up
  E/AndroidRuntime(6274):     at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:271)
  E/AndroidRuntime(6274):     at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:273)
  E/AndroidRuntime(6274):     at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:273)
  E/AndroidRuntime(6274):     at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:216)
  E/AndroidRuntime(6274):     at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:288)
  E/AndroidRuntime(6274):     at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:273)
  E/AndroidRuntime(6274):     at com.mongodb.DB.getCollectionNames(DB.java:400)
  E/AndroidRuntime(6274):     at com.myproject.examplemongodb.ActivityMain$1.run(ActivityMain.java:89)
  E/AndroidRuntime(6274):     at java.lang.Thread.run(Thread.java:841)
  </code></pre>
  
  <p><strong>Notes</strong>:</p>
  
  <ul>
  <li>I am using the newest <a href="http://central.maven.org/maven2/org/mongodb/mongo-java-driver/" rel="nofollow noreferrer">mongo-java-driver</a> (currently 2.11.3).</li>
  <li>I am connecting remotely to database (non-localhost).</li>
  <li>Another <a href="https://stackoverflow.com/questions/11308750/com-mongodb-mongoexception-not-talking-to-master-and-retries-used-up">question</a> mentions this error, but OP is using different drivers and his solution does not work for Android/Java.</li>
  </ul>
  
  <p><strong>Possible solution</strong>:</p>
  
  <ul>
  <li>It appears that closing the connection from the app allowed the next run to work properly. But, I'm still worried about being able allow concurrent connections, which I would definitely like to do.
  
  <ul>
  <li>Update: I have wrapped a mongodb log in and log out around each of my queries going to the server, but the error still seems to show up intermittently. So far, it seems that write work every time, but reads only work half the time. The other half of the time is the posted error.</li>
  </ul></li>
  </ul>