When a transaction commits, it checks collections involved and adds to migration document queues if necessary. To do this, we check if a MigrationSourceManager variable exists on the CollectionShardingRuntime. Due to the fact that transactions stash locks, we skip the collection lock check assertion via the get_UNSAFE method. Skipping the collection lock assertion is fine, since we guarantee at storage commit time that collection locks are held. However, we also skip acquisition of the CSRLock.
Since we don't take the CSRLock, we currently have the pointer to the MigrationSourceManager and chunk cloner without any concurrency guarantees. This means that the pointer to the MigrationSourceManager can go out of scope at any time.
We take the CSRLock in exclusive mode in order to unregister the pointer/memory for the MigrationSourceManager. We can take the CSRLock in read mode during observing transaction commit to guarantee that we don't remove the pointer while the underlying MigrationSourceManager is in use.