Open ofirreuv72 opened 5 years ago
I've never used Thread Sanitizer before so can't say why it gives such a warning. I'd suggest playing with a minimum code snippet that would use a recursive lock and recursive function calls if you are curious. It might be just a sanitizer not playing well with recursive locks.
i do think there is a race condition here.
the inContext function is protected by the lock, but also setting the context object.
context = Context(
key: key,
injectedInType: injectedInType,
injectedInProperty: injectedInProperty,
inCollaboration: inCollaboration
)
the line at Resolve.swift ~ 141
return try inContext(key:key, injectedInType: context?.resolvingType) {
is not protected by a lock and it is access the context object which is not protected.
i think we need to protect the access to context?.resolvingType
making the change below fix this issue, but i am not sure if this is the correct fix.
| =>git diff
diff --git a/Sources/Resolve.swift b/Sources/Resolve.swift
index 4cf0791..b84e8ca 100644
--- a/Sources/Resolve.swift
+++ b/Sources/Resolve.swift
@@ -46,7 +46,9 @@ extension DependencyContainer {
- seealso: `register(_:type:tag:factory:)`
*/
public func resolve<T>(tag: DependencyTagConvertible? = nil) throws -> T {
- return try _resolve(tag: tag) { (factory: () throws -> T) in try factory() }
+ return try threadSafe {
+ return try _resolve(tag: tag) { (factory: () throws -> T) in try factory() }
+ }
}
/**
@ofirreuv72 is this still relevant?
Hi,
enable thread sanitiser in Xcode.
I used the sample app provided and added this code. in application didFinishLaunchingWithOptions after the configure function.
i am getting the error below
please advise