When we catch an ErrorCodes::ShardInvalidatedForTargeting in here, we end up executing the getCollectionRoutingInfoWithRefresh function. Part of the work of this function is done asynchronously and it doesn't check wether the CatalogCache is still alive.
The failure happened when executing the resharding_destined_recipient_test.cpp unit tests. More concretely, the data race was between these two points: tearDown and [assertThrow
https://github.com/mongodb/mongo/blob/45637f4d481c8badd6d5a2d95dcb8ae947c78c92/src/mongo/db/s/resharding_destined_recipient_test.cpp#L266] |
We should change the test, waiting until all the asynchronous work was completed before tearing down everything.