Inconsistent mongosh `isBalancerRunning()` output (mongodb 5.0)?

I am testing stopping the balancer using mongosh (mongodb 5.0). After issuing:

sh.stopBalancer()
{
  ok: 1,
  '$clusterTime': {
    clusterTime: Timestamp({ t: 1647280772, i: 2 }),
    signature: {
      hash: Binary(Buffer.from("3b6fce0d15bd3a4942d57d1c7a43b20bae66f79d", "hex"), 0),
      keyId: Long("7068691758833467401")
    }
  },
  operationTime: Timestamp({ t: 1647280772, i: 2 })
}

However if I then run:

[direct: mongos] test> !sh.isBalancerRunning()
false

(Note the ! in the statement above)
I am expecting above to return true since just before I issued the stop balancer command and my db has no absolutely load so no transactions can be really happening.

Also related, after stopping the balancer the documentation (https://docs.mongodb.com/manual/tutorial/manage-sharded-cluster-balancer/#disable-the-balancer) says to wait for ongoing transactions using:

use config
while( sh.isBalancerRunning() ) {
          print("waiting...");
          sleep(1000);
}

However if I run it the loop keeps waiting forever.

For extra info, the output of sh.isBalancerRunning() is:

direct: mongos] test> sh.isBalancerRunning()
{
  mode: 'off',
  inBalancerRound: false,
  numBalancerRounds: Long("5017"),
  ok: 1,
  '$clusterTime': {
    clusterTime: Timestamp({ t: 1647280864, i: 1 }),
    signature: {
      hash: Binary(Buffer.from("c1cee2f3fddfe7ffd663d492951ecab38c0cd988", "hex"), 0),
      keyId: Long("7068691758833467401")
    }
  },
  operationTime: Timestamp({ t: 1647280864, i: 1 })
}

If I start the balancer again:

[direct: mongos] test> sh.startBalancer()
{
  ok: 1,
  '$clusterTime': {
    clusterTime: Timestamp({ t: 1647281048, i: 4 }),
    signature: {
      hash: Binary(Buffer.from("838d5256c25e52fd466e94d599529953b2331e86", "hex"), 0),
      keyId: Long("7068691758833467401")
    }
  },
  operationTime: Timestamp({ t: 1647281048, i: 4 })
}
[direct: mongos] test> sh.isBalancerRunning()
{
  mode: 'full',
  inBalancerRound: false,
  numBalancerRounds: Long("5036"),
  ok: 1,
  '$clusterTime': {
    clusterTime: Timestamp({ t: 1647281051, i: 1 }),
    signature: {
      hash: Binary(Buffer.from("cc695fd5020560d7a0275f7d4f94d6a94579c3d7", "hex"), 0),
      keyId: Long("7068691758833467401")
    }
  },
  operationTime: Timestamp({ t: 1647281051, i: 1 })
}
1 Like