apple / swift-service-discovery

A service discovery API for Swift.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Thread safety rules need to be clarified.

Lukasa opened this issue · comments

The ServiceDiscovery protocol currently does not constrain whether or not implementers must be thread safe. This makes it very hard to use in a generic context, as the only reasonable assumption becomes that some implementations will not be thread safe, and thus all must be treated as not thread safe.

Can we clarify this uncertainty? What are the rules on thread-safety for ServiceDiscovery implementations?

I ask in particular because InMemoryServiceDiscovery is not thread-safe. It's a reference type with two mutable pieces of state, which requires that all calls come from one thread. It even does a slightly dodgy maneuver with DispatchQueue.global().async in lookup which kinda looks like it's supposed to support concurrent access but does not, and indeed makes the entire class very brittle.