orlandos-nl / MongoKitten

Native MongoDB driver for Swift, written in Swift

Home Page:https://orlandos.nl/docs/mongokitten/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Race condition in MongoCluster when using lazy connection to SRV hostname

Obbut opened this issue · comments

Describe the bug

In MongoCluster, resolving of SRV hostnames is kicked off in .init(lazyConnectingTo:logger:eventLoopGroup:). This happens in asynchronously in a task:

Task {
// Kick off the connection process
try await resolveSettings()
scheduleDiscovery()
}

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.