Closed Obbut closed 1 year ago
Describe the bug
In MongoCluster, resolving of SRV hostnames is kicked off in .init(lazyConnectingTo:logger:eventLoopGroup:). This happens in asynchronously in a task:
.init(lazyConnectingTo:logger:eventLoopGroup:)
https://github.com/orlandos-nl/MongoKitten/blob/0ca7b302498f711b4d0f10f2a8ad2ccb22a2c008/Sources/MongoClient/Cluster.swift#L167-L172
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.
resolveSettings
Describe the bug
In MongoCluster, resolving of SRV hostnames is kicked off in
.init(lazyConnectingTo:logger:eventLoopGroup:)
. This happens in asynchronously in a task:https://github.com/orlandos-nl/MongoKitten/blob/0ca7b302498f711b4d0f10f2a8ad2ccb22a2c008/Sources/MongoClient/Cluster.swift#L167-L172
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.