Not unless you want to write WeakThreadSafeDic<TKey,TVal>

On Tue, Feb 3, 2009 at 1:17 PM, Fabio Maulo <[email protected]> wrote:

> NHibernate.Util.ThreadSafeDictionary<TKey, TValue> ?
>
> 2009/2/3 Ayende Rahien <[email protected]>
>
> That is a hack.
>> The issue is still there, but just harder to hit.
>> We have to either make WeakHashtable thread safe (probably very hard) or
>> lock around setting/getting from it
>>
>>
>> On Tue, Feb 3, 2009 at 12:05 PM, Pierre Henri Kuate <[email protected]>wrote:
>>
>>>
>>> After further investigation, I think that here is how the issue
>>> occurs:
>>>
>>> There is only one Worker per SessionFactory so multiple calls to
>>> TransactionalWorker.PerformWork() can be running on different threads
>>> at the same time.
>>> The only line that changes the WeakHashtable is:
>>> synchronizationPerTransaction[transaction] = txSync;
>>>
>>> Looking at its implementation, we can see that it scavenges first then
>>> set the value. So if a scavenge is running on one thread while a set
>>> is being performed on another, we get that exception.
>>>
>>> To test this theory, I modified the code like this:
>>> synchronizationPerTransaction.SetWithoutScavenging(transaction,
>>> txSync); // Which just set the value in the innerHashtable
>>> And that exception hasn't occur after multiple tests.
>>>
>>> What do you think about this solution? Hack or Fix? :)
>>>
>>> Note that this require adding a method to
>>> NHibernate.Util.WeakHashtable and I wonder if it doesn't reveal a
>>> larger problem...
>>>
>>>
>>> On Feb 3, 10:21 am, Ayende Rahien <[email protected]> wrote:
>>> > looks like an obivious multi threading issue. I'll look into it a bit.
>>> >
>>> > On Tue, Feb 3, 2009 at 9:58 AM, Pierre Henri Kuate <[email protected]
>>> >wrote:
>>> >
>>> >
>>> >
>>> > > Hi all,
>>> >
>>> > > I have access to a 8-core workstation and I use it to stress test my
>>> > > project.
>>> > > I noticed that the concurrency tests in NHibernate.Search sometimes
>>> > > fail with the following exception:
>>> >
>>> > > System.InvalidOperationException: Collection was modified;
>>> enumeration
>>> > > operation may not execute.
>>> > >   at System.Collections.Hashtable.HashtableEnumerator.MoveNext()
>>> > >   at NHibernate.Util.WeakHashtable.Scavenge() in C:\Dev\NHibernate
>>> > > \NHibernate\Util\WeakHashtable.cs:line 150
>>> > >   at NHibernate.Util.WeakHashtable.set_Item(Object key, Object value)
>>> > > in C:\Dev\NHibernate\NHibernate\Util\WeakHashtable.cs:line 198
>>> > >   at NHibernate.Search.Backend.Impl.TransactionalWorker.PerformWork
>>> > > (Work work, ISessionImplementor session) in C:\Dev\NHibernate
>>> > > \NHibernate.Search\Backend\Impl\TransactionalWorker.cs:line 28
>>> > >   at NHibernate.Search.Event.FullTextIndexEventListener.ProcessWork
>>> > > (Object entity, Object id, WorkType workType, AbstractEvent e) in C:
>>> > > \Dev\NHibernate\NHibernate.Search\Event
>>> > > \FullTextIndexEventListener.cs:line 54
>>> > >   at NHibernate.Search.Event.FullTextIndexEventListener.OnPostUpdate
>>> > > (PostUpdateEvent e) in C:\Dev\NHibernate\NHibernate.Search\Event
>>> > > \FullTextIndexEventListener.cs:line 94
>>> > >   at NHibernate.Action.EntityUpdateAction.PostUpdate() in C:\Dev
>>> > > \NHibernate\NHibernate\Action\EntityUpdateAction.cs:line 172
>>> > >   at NHibernate.Action.EntityUpdateAction.Execute() in C:\Dev
>>> > > \NHibernate\NHibernate\Action\EntityUpdateAction.cs:line 128
>>> > >   at NHibernate.Engine.ActionQueue.Execute(IExecutable executable) in
>>> > > C:\Dev\NHibernate\NHibernate\Engine\ActionQueue.cs:line 130
>>> > >   at NHibernate.Engine.ActionQueue.ExecuteActions(IList list) in C:
>>> > > \Dev\NHibernate\NHibernate\Engine\ActionQueue.cs:line 113
>>> > >   at NHibernate.Engine.ActionQueue.ExecuteActions() in C:\Dev
>>> > > \NHibernate\NHibernate\Engine\ActionQueue.cs:line 147
>>> > >   at
>>> > >
>>> NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions
>>> > > (IEventSource session) in C:\Dev\NHibernate\NHibernate\Event\Default
>>> > > \AbstractFlushingEventListener.cs:line 241
>>> > >   at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush
>>> > > (FlushEvent event) in C:\Dev\NHibernate\NHibernate\Event\Default
>>> > > \DefaultFlushEventListener.cs:line 19
>>> > >   at NHibernate.Impl.SessionImpl.Flush() in C:\Dev\NHibernate
>>> > > \NHibernate\Impl\SessionImpl.cs:line 1215
>>> > >   at NHibernate.Transaction.AdoTransaction.Commit() in C:\Dev
>>> > > \NHibernate\NHibernate\Transaction\AdoTransaction.cs:line 177
>>> > >   at NHibernate.Search.Tests.Worker.WorkerTestCase.ReverseWork(Object
>>> > > state) in C:\Dev\NHibernate\NHibernate.Search.Tests\Worker
>>> > > \WorkerTestCase.cs:line 216
>>> >
>>> > > Note that it also occurs on my Core 2 Duo, but far less often.
>>> >
>>> > > Have you ever experienced this issue? Any suggestions on how to fix
>>> it?
>>>
>>>
>>
>>
>>
>
>
> --
> Fabio Maulo
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"NHibernate Contrib - Development Group" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com.ar/group/nhcdevs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to