title: MongoDB stuck creating index with "Index Build: draining writes received during build" message
body: <p>I have 4 rows in the <code>test</code> collection:</p>
  <pre><code>{ &quot;_id&quot; : ObjectId(&quot;5f4ce50e19b13337216dd477&quot;), &quot;test&quot; : 1 }
  { &quot;_id&quot; : ObjectId(&quot;5f4ce50e19b13337216dd478&quot;), &quot;test&quot; : 2 }
  { &quot;_id&quot; : ObjectId(&quot;5f4ce50e19b13337216dd479&quot;), &quot;test&quot; : 3 }
  { &quot;_id&quot; : ObjectId(&quot;5f4ce50e19b13337216dd47a&quot;), &quot;test&quot; : 4 }
  </code></pre>
  <p>After running <code>db.test.createIndex({test:1},{background:1});</code> to create an index, it just hangs. It was hanging for at least a few hours. Here is what I found in the db.currentOp() about this operation:</p>
  <pre><code>{
      &quot;type&quot; : &quot;op&quot;,
      &quot;host&quot; : &quot;HOSTNAME:27017&quot;,
      &quot;desc&quot; : &quot;IndexBuildsCoordinatorMongod-13&quot;,
      &quot;active&quot; : true,
      &quot;currentOpTime&quot; : &quot;2020-08-31T12:11:13.159+00:00&quot;,
      &quot;opid&quot; : 8721867,
      &quot;secs_running&quot; : NumberLong(20),
      &quot;microsecs_running&quot; : NumberLong(20888590),
      &quot;op&quot; : &quot;command&quot;,
      &quot;ns&quot; : &quot;test.test&quot;,
      &quot;command&quot; : {
          &quot;createIndexes&quot; : &quot;test&quot;,
          &quot;indexes&quot; : [
              {
                  &quot;v&quot; : 2,
                  &quot;key&quot; : {
                      &quot;test&quot; : 1
                  },
                  &quot;name&quot; : &quot;test_1&quot;,
                  &quot;background&quot; : 1
              }
          ],
          &quot;lsid&quot; : {
              &quot;id&quot; : UUID(&quot;07b43083-8ab9-4bcb-8768-919a3f27655f&quot;)
          },
          &quot;$clusterTime&quot; : {
              &quot;clusterTime&quot; : Timestamp(1598875647, 409),
              &quot;signature&quot; : {
                  &quot;hash&quot; : BinData(0,&quot;+/YcdPyQriT8RL1LtFUhxe2BtCE=&quot;),
                  &quot;keyId&quot; : NumberLong(&quot;6861636045532823556&quot;)
              }
          },
          &quot;$db&quot; : &quot;test&quot;
      },
      &quot;msg&quot; : &quot;Index Build: draining writes received during build&quot;,
      &quot;numYields&quot; : 0,
      &quot;locks&quot; : {
  
      },
      &quot;waitingForLock&quot; : false,
      &quot;lockStats&quot; : {
          &quot;ReplicationStateTransition&quot; : {
              &quot;acquireCount&quot; : {
                  &quot;w&quot; : NumberLong(6)
              }
          },
          &quot;Global&quot; : {
              &quot;acquireCount&quot; : {
                  &quot;r&quot; : NumberLong(1),
                  &quot;w&quot; : NumberLong(4)
              }
          },
          &quot;Database&quot; : {
              &quot;acquireCount&quot; : {
                  &quot;r&quot; : NumberLong(1),
                  &quot;w&quot; : NumberLong(4)
              }
          },
          &quot;Collection&quot; : {
              &quot;acquireCount&quot; : {
                  &quot;r&quot; : NumberLong(1),
                  &quot;w&quot; : NumberLong(3),
                  &quot;W&quot; : NumberLong(1)
              }
          },
          &quot;Mutex&quot; : {
              &quot;acquireCount&quot; : {
                  &quot;r&quot; : NumberLong(4)
              }
          }
      },
      &quot;waitingForFlowControl&quot; : false,
      &quot;flowControlStats&quot; : {
          &quot;acquireCount&quot; : NumberLong(3),
          &quot;timeAcquiringMicros&quot; : NumberLong(1)
      }
  }
  </code></pre>
  <p>This <code>Index Build: draining writes received during build</code> makes no sense since there was no read/writes to the <code>test</code> collection during index creation.</p>
  <p>Also index creation hangs only in non-empty collection. Index creates successfully in empty collection.</p>
  <p>What might be an issue in this case? I'm out of ideas.</p>