-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: Assertion failure in Syscache
PostPosted: Wed Sep 20, 2006 2:16 pm 
Newbie

Joined: Tue Aug 01, 2006 12:42 pm
Posts: 11
NHibernate version: 1.0.2.0

Hello All,

I'm using the syscache from the contrib along with Nhibernate, and I find that very rarely, the NHibernate.AssertionFailure below fires. It is very difficult to reproduce, and thus has been challenging to debug.

The exception is stating that there is already an entry in syscache's _map for this object, when we're trying to .Add() it (so the _map, which is Hashtable, throws).

The code on top of the stack trace below is just .Save()'ing objects with Guids as keys. The guids are obtained from Guid.NewGuid() so it cannot be the case that 2 different objects have the same key.

This seems similar to a post fom July in the forum, which sadly has no replies: http://forum.hibernate.org/viewtopic.php?t=962045

Any ideas are most appreciated. Many thanks.


Full stack trace of exception that occurs:
************** Exception Text **************
NHibernate.TransactionException: Commit failed with SQL exception ---> NHibernate.AssertionFailure: Exception releasing cache locks ---> System.ArgumentException: Item has already been added. Key in dictionary: 'NHibernate-Cache:Msg.Framework.RUdpTransport.RMOutMsg:c24d7914-0898-47d7-a4a8-40c652c9db39@-1965736198' Key being added: 'NHibernate-Cache:Msg.Framework.RUdpTransport.RMOutMsg:c24d7914-0898-47d7-a4a8-40c652c9db39@-1965736198'
at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
at System.Collections.Hashtable.Add(Object key, Object value)
at NHibernate.Caches.SysCache.SysCache.Put(Object key, Object value)
at NHibernate.Cache.ReadWriteCache.AfterInsert(Object key, Object value, Object version)
at NHibernate.Impl.ScheduledInsertion.AfterTransactionCompletion(Boolean success)
at NHibernate.Impl.SessionImpl.AfterTransactionCompletion(Boolean success)
--- End of inner exception stack trace ---
at NHibernate.Impl.SessionImpl.AfterTransactionCompletion(Boolean success)
at NHibernate.Transaction.AdoTransaction.Commit()
--- End of inner exception stack trace ---


Top
 Profile  
 
 Post subject: Syscache issues
PostPosted: Wed Sep 20, 2006 4:30 pm 
Newbie

Joined: Tue Aug 01, 2006 12:42 pm
Posts: 11
Hello All,

FYI, I've taken a bit of time and looked at the syscache code, and it looks like it suffers from a race condition.

NHibernate's use of it is threadsafe (behind a lock) but the syscache listens to callbacks from the WebCache that uses when objects expire. Since this map is not locked, NH's thread and this callback thread can race and collide on this _map. This fix for this is to lock the map when we access it.

Is this syscache contribution in a project somewhere where I can look at a bug list, or is just a random piece of code some sent...somewhere to be included in the NH contrib?

As for the issue I encountered in the original post, I've noticed that when doing Insert()'s, NHibernate seems to call Put() on the cache twice for the same object. Thus, if the object is evicted from the cache but the callback thread has not called into us to update the map, we can, on insertions, end up with this sequence:

1. First Put() from NH - puts the object into the cache and map.
2. cache evicts object, starts callback.
3. Second Put() from NH comes in and, seeing that the object is not in the cache, trys to .Add() it to the map, which throws because the id is still there.

The solution for this is to change the .Add() to a [] = in the SysCache::Put() else clause.

Evan

EDIT: Changed a map to a cache in the #3 point in the list, so it makes sense.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 20, 2006 5:46 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
The NHibernate issue tracking system is here.

Have you tried using the latest code?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 21, 2006 12:57 pm 
Newbie

Joined: Tue Aug 01, 2006 12:42 pm
Posts: 11
I'm using the syscache code from the official NHibernateContrib here: http://sourceforge.net/project/showfile ... p_id=73818

Is there other code I should be using, beyond that in this release?

If so, could you point me towards it? Many thanks.

Evan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 02, 2006 1:50 am 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
Hi Evan,

What is your current status with this issue? I am also seeing this occasionally and it is frustratingly difficult to pinpoint the cause of it or figure out how to implement some safety measures/workarounds.

My site is in development at the moment with very low traffic and I am very worried that this error will go banana's when there is a high volume of traffic on the site. The error seems to "stick" once it has occured and I usually have to reset the web process to clear the cache...not nice!

Would appreciate any assistance you can provide on this.

Thanks,

Jason


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 02, 2006 3:34 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
Have you tried a different cache? It would help to isolate whether the problem is in SysCache, NHibernate, or somewhere else.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 02, 2006 4:10 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
This bug should be fixed in 1.0.3 which will be out tomorrow.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 02, 2006 4:19 pm 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
That's great news...thanks guys.

I was wondering if my problem might be due to running 2 copies of the application on my computer and the cache being shared in some way...is that possible? However, the problem has occurred when I shutdown all of the web processes and just ran one of the applications so I figured there might be some other cause too.

Anyway, I have added different cache region prefixes for each application just in case.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 04, 2006 2:45 am 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
FYI: I upgraded to 1.0.3 and this problem does seem to have been resolved.

Thanks,

Jason


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.