Found multithreading issues in iso storage

Dec 5, 2011 at 10:11 PM

I've found a couple of areas where Sterling fails in multithreading when writing to two different tables (each on their own thread).  In two was able to fix the code but a third/forth I couldn't find the source of the sync issue.  During debug I'm flatlining the IsoStorage so each case is as if it was the first time trying to create the database.

Case 1:

IsoStorageHelper.EnsureDirectory(string path):  I get a file IO error, was able to do a ugly fix by creating a lock object and then only allowing one thread at a time do the _paths.Contains(path) code block.  By visual inspection the sync code looks right but there might be an issue in PathLock.GetLock(string path).

 

Case 2:

AggregateSerializer.CanSerialize(Type targetType): I get a duplicate Index error, was able to fix by double checking to make sure the _serializerCache list doesn't add the targetType before add.  In a multithread enviroment I was getting two threads trying to check the type int at the same time.  Both would pass the first two condition checks and then one would lock and add the int.  When the second thread got unlocked, it would then try to add the int as well.  By adding the double check in the lock code it prevents the error.

 

Case 3/4:

IsoStorageHelper.GetWriter(string path): I get a file IO error.  The error goes away if I force the two threads to sync their writes, but since they are two different tables I don't see the issue.  IsolatedStorageDriver.SerializeTypes() and IsolatedStorageDriver.Save(Type type, int keyIndex, btye[] btyes) where the two places where it was being called from that was failing.  The only thing I can think of is that IsoStorage only allows one file to be writen at a time.

 

If I need to create a small demo application to demostrate the issues, I will do that on request.

Dec 5, 2011 at 10:38 PM

To add a little more, when using the ElevatedTrustDriver I don't have any multithreading issues (once case 2 was fixed).

Mar 8, 2012 at 2:45 PM

I'm having similar issues - do you mind posting the 'fixes' you made?

Thanks

jack