sapiens/SqlFu

Concurrency issue with TableInfo in v3.3.3

Closed this issue · 1 comments

We are having a problem in a high concurrency environment when trying to use DbConnection.InsertAsync. Further inspection showed that the issue is with TableInfo._cache which is a Dictionary instead of ConcurrentDictionary (a change like this was applied in v3.3.3 on TableInfoFactory). It looks like TableInfos are fetched from the factory where the cache is using ConcurrentDictionary (so we can have multiple references from different threads to the same TableInfo), but the TableInfo's internal cache is of Dictionary<string,TableSqlCache> type.

System.NullReferenceException: Object reference not set to an instance of an object.
at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) at System.Collections.Generic.ListUtils.GetValueOrCreate[T,V](IDictionary2 dict, T key, Func1 factory) at SqlFu.Builders.Crud.InsertSqlBuilder.GetCommandConfiguration() at SqlFu.CrudHelpers.InsertAsync[T](DbConnection db, T data, CancellationToken cancel, Action1 cfg)

OK, try the new version.