title: Running db.fsyncUnlock() after db.fsyncLock() on mongo tool results in stuck process
body: <p>I log in to my mongodb instance using</p>
  
  <pre><code>mongo admin -u &lt;user&gt; -p &lt;pass&gt; --port &lt;port&gt;
  </code></pre>
  
  <p>And then run the following commands.</p>
  
  <pre><code>rs0:SECONDARY&gt; db.fsyncLock()
  {
    "info" : "now locked against writes, use db.fsyncUnlock() to unlock",
    "seeAlso" : "http://dochub.mongodb.org/core/fsynccommand",
    "ok" : 1
  }
  rs0:SECONDARY&gt; db.fsyncUnlock()
  </code></pre>
  
  <p>The unlock command stays stuck for a long time. If I press CTRL-C, I get the following trace with <code>Assertion failure isABSONObj() src/mongo/bson/bson-inl.h 1831</code></p>
  
  <pre><code>2015-05-13T10:08:55.455+0000 Assertion failure isABSONObj() src/mongo/bson/bson-inl.h 183
  2015-05-13T10:08:55.458+0000 0x868a51 0x816b59 0x7f9cce 0x7e06be 0x61b2e0 0x7fbcb07fec60 0x7fbcb159eab9 0x8266f2 0x826729 0x826775 0x81edfc 0x81fcc6 0x8202b1 0x66d8e5 0x699f9a 0x66359a 0x680574 0x7c4743 0x7a71f9 0x7197bb52579 
  mongo(_ZN5mongo15printStackTraceERSo+0x21) [0x868a51]
  mongo(_ZN5mongo10logContextEPKc+0x159) [0x816b59]
  mongo(_ZN5mongo12verifyFailedEPKcS1_j+0x17e) [0x7f9cce]
  mongo(_ZNK5mongo11shell_utils18ConnectionRegistry30killOperationsOnAllConnectionsEb+0x45e) [0x7e06be]
  mongo(_Z10quitNicelyi+0x40) [0x61b2e0] /lib64/libc.so.6(+0x33c60) [0x7fbcb07fec60]
  /lib64/libpthread.so.0(recv+0x79) [0x7fbcb159eab9]
  mongo(_ZN5mongo6Socket5_recvEPci+0x22) [0x8266f2]
  mongo(_ZN5mongo6Socket11unsafe_recvEPci+0x9) [0x826729]
  mongo(_ZN5mongo6Socket4recvEPci+0x35) [0x826775]
  mongo(_ZN5mongo13MessagingPort4recvERNS_7MessageE+0x9c) [0x81edfc]
  mongo(_ZN5mongo13MessagingPort4recvERKNS_7MessageERS1_+0x36) [0x81fcc6]
  mongo(_ZN5mongo13MessagingPort4callERNS_7MessageES2_+0x31) [0x8202b1]
  mongo(_ZN5mongo18DBClientConnection4callERNS_7MessageES2_bPSs+0x55) [0x66d8e5]
  mongo(_ZN5mongo14DBClientCursor4initEv+0xba) [0x699f9a]
  mongo(_ZN5mongo12DBClientBase5queryERKSsNS_5QueryEiiPKNS_7BSONObjEii+0xea) [0x66359a]
  mongo(_ZN5mongo18DBClientConnection5queryERKSsNS_5QueryEiiPKNS_7BSONObjEii+0xa4) [0x680574]
  mongo(_ZN5mongo9mongoFindEPNS_7V8ScopeERKN2v89ArgumentsE+0x3d3) [0x7c4743]
  mongo(_ZN5mongo7V8Scope10v8CallbackERKN2v89ArgumentsE+0x89) [0x7a71f9][0x7197bb52579]
  </code></pre>
  
  <p>When I login again and run the following function to check if the lock is held:</p>
  
  <pre><code>serverIsLocked = function () {
                   var co = db.currentOp();
                   if (co &amp;&amp; co.fsyncLock) {
                       return true;
                   }
                   return false;
               }
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>rs0:SECONDARY&gt; serverIsLocked()
  true
  rs0:SECONDARY&gt; db.fsyncUnlock()
  </code></pre>
  
  <p>and db.fsyncUnlock() is stuck again. Not sure what is going on and how to unlock the DB. The documentation for <code>fsync</code> has the following:</p>
  
  <blockquote>
    <p>WARNING
    When calling fsync with lock, ensure that the connection remains open to allow a subsequent call to db.fsyncUnlock().</p>
    
    <p>Closing the connection may make it difficult to release the lock.</p>
  </blockquote>
  
  <p>I was initially trying to lock and unlock using <code>--eval</code>. Could this be an issue? What is the way to unlock the db now?</p>
  
  <pre><code>mongo admin --eval "printjson(db.fsyncLock())"
  mongo admin --eval "printjson(db.fsyncUnlock())"
  </code></pre>
  
  <p>All of this is part of a mongodump script I am writing. </p>
  
  <p>UPDATE: I am following this post in creating my script: <a href="http://www.codeproject.com/Tips/547759/Automating-backup-for-MongoDB-using-CRON-and-S-CMD" rel="nofollow">http://www.codeproject.com/Tips/547759/Automating-backup-for-MongoDB-using-CRON-and-S-CMD</a></p>
  
  <p>UPDATE2: Looks like post version 2.2, <code>mongodump</code> should not be used wit <code>db.fsyncLock()</code>. I will remove that from my script and add <code>--oplog</code> flag to <code>mongodump</code>. However, I still need to figure out how to unlock my DB. </p>