The collection can be dropped if the balancer loses the distlock during the migration. Then drop can acquire the distlock and run during the migration.
This line of code,
css->getMetadata()->getCollVersion()
can segfault. If the collection is not sharded (say it has been dropped), CollectionShardingState::get creates a CollectionShardingState, which creates an empty MetadataManager with no active metadata. When MetadataManager::getActiveMetadata (via css->getMetadata) is called, it returns an empty ScopedCollectionMetadata object. Then when the ScopedCollectionMetadata object is dereferenced for getCollVersion, a nullptr is accessed.
This might be solved by additionally checking that css->getMetadata() returns true before proceeding with getCollVersion. css->getMetadata() returns a ScopedCollectionMetadata, which has a bool operator function defined to return true if it actually has a CollectionMetadata.
Should survey all of css->getMetadata usages to make use they won't segfault.
Further check in other places in MigrationSourceManager that the collection has not been dropped or recreated (it would have a different epoch in the version).