Race condition in MongoCluster when using lazy connection to SRV hostname
Obbut opened this issue · comments
Robbert Brandsma commented
Describe the bug
In MongoCluster, resolving of SRV hostnames is kicked off in .init(lazyConnectingTo:logger:eventLoopGroup:)
. This happens in asynchronously in a task:
MongoKitten/Sources/MongoClient/Cluster.swift
Lines 167 to 172 in 0ca7b30
Because the result of this (which happens in resolveSettings
) is not awaited before creating connections, a race condition exists: connections that are lazily created before the hostname resolution is complete, will connect to the wrong hostname.