Skip to content

Commit

Permalink
Threading fix for IntercepterLibrary:
Browse files Browse the repository at this point in the history
Racecondition issue can occur if _analyzedInterceptors.Clear() is invoked inside body of (1) prior to indexing in (2):

if (_analyzedInterceptors.ContainsKey(type)) // (1)
{
    return _analyzedInterceptors[type];      // (2)
}
  • Loading branch information
ahjohannessen authored and joshuaflanagan committed Aug 28, 2011
1 parent 173cb60 commit a55ed22
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions Source/StructureMap/Interceptors/InterceptorLibrary.cs
Expand Up @@ -29,22 +29,20 @@ public void ImportFrom(InterceptorLibrary source)

public CompoundInterceptor FindInterceptor(Type type)
{
if (_analyzedInterceptors.ContainsKey(type))
CompoundInterceptor interceptor;
if (!_analyzedInterceptors.TryGetValue(type, out interceptor))
{
return _analyzedInterceptors[type];
}

lock (_locker)
{
if (!_analyzedInterceptors.ContainsKey(type))
lock (_locker)
{
TypeInterceptor[] interceptorArray =
_interceptors.FindAll(i => i.MatchesType(type)).ToArray();
_analyzedInterceptors.Add(type, new CompoundInterceptor(interceptorArray));
if (!_analyzedInterceptors.TryGetValue(type, out interceptor))
{
var interceptorArray = _interceptors.FindAll(i => i.MatchesType(type)).ToArray();
interceptor = new CompoundInterceptor(interceptorArray);
_analyzedInterceptors.Add(type, interceptor);
}
}
}

return _analyzedInterceptors[type];
return interceptor;
}

public InstanceInterceptor[] FindInterceptors(Type type)
Expand Down

0 comments on commit a55ed22

Please sign in to comment.