Mongos can return the wrong topologyVersion in state change error responses to the client. Instead of returning its own topologyVersion, mongos can return the topologyVersion of a shard member in some error responses.
I've attach a reproduction script using failCommand (reproMongosWrongTopologyVersion.js). It's also possible to trigger the same bug using a real shutdown or replSetStepDown event. To reproduce:
- Start a cluster. Mine has 1 mongos and a 1 member shard.
- Note the topologyVersion reported by the mongos.
- Insert into test.test
- Run an operation on mongos, my example uses findAndModify but I imagine other commands will also reproduce.
- At the same time, cause the mongos-mongod operation to fail. This can be done with failCommand, shutdown:1, etc...
- See the operation fails and mongos returns a error with the incorrect topologyVersion.
The attach repro script's output (notice the different topologyVersion fields both reported by mongos):
It's possible this could be fixed by
SERVER-50549 but I wanted to call out this bug separately.