Possible scalability issue in WorkflowFoundationPageFlowFactory.cs

Topics: Web Client Software Factory, Project Management Forum, User Forum
Mar 21, 2007 at 8:51 AM
I noticed an invalid implementation of a reader / writer lock, that I wanted to bring to your attention, due to potential scalability issues.

In the included method below, an exclusive lock on the instance variable, _readerLockerDefs is obtained, preventing any other threads from reading the cache at the same time. The _writerLockerDefs is actually redundant here, since it is also an instance variable.

Either a ReaderWriterLock or a custom implementation of the Reader/Writer pattern is needed.

Cheers,

Stuart

private WorkflowFoundationPageFlowDefinition GetOrCreateDefinition(Type pageFlowType, WorkflowInstance instance)
{
    WorkflowFoundationPageFlowDefinition cachedDefinition;
    lock (_readerLockerDefs)
    {
        if (!_workflowDefinitionsCache.TryGetValue(pageFlowType, out cachedDefinition))
        {
            lock (_writerLockerDefs)
            {
                if (!_workflowDefinitionsCache.TryGetValue(pageFlowType, out cachedDefinition))
                {
                    cachedDefinition = new WorkflowFoundationPageFlowDefinition((Activities.PageFlow)instance.GetWorkflowDefinition());
                    _workflowDefinitionsCache.Add(pageFlowType, cachedDefinition);
                }
            }
        }
    }
    return cachedDefinition;
}
Coordinator
Mar 21, 2007 at 9:22 PM
This discussion has been copied to Work Item 9067. You may wish to continue further discussion there.
Coordinator
Mar 21, 2007 at 9:23 PM
Thanks for the heads up.