Intermittent NHibernate issue

Topics: Administration, General
Jul 10, 2014 at 7:50 PM
On several occasions in the past couple months our Orchard website (v1.8) has started returning 200 codes with empty responses for all pages on the site. Each time, only restarting the site's app pool has resolved the issue.

I opened an issue here a few weeks ago: https://orchard.codeplex.com/workitem/20775.

Today, it happened again but this time it was a different NHibernate exception (full stack trace at the end):
NHibernate.AssertionFailure: collection was processed twice by flush()
This exception was thrown for every request to the site until I restarted the app pool, it was not specific to certain pages or types of content. I have no idea how to reproduce the issue and it happens very rarely, but effectively takes down the whole site until someone intervenes and restarts the app pool. I'm starting to wonder if I have a corrupt NHibernate configuration or something. Is that possible?

Any ideas or suggestions would be greatly appreciated.
2014-07-10 11:11:59,203 [32] Orchard.Exceptions.DefaultExceptionPolicy - Default - An unexpected exception was caught
 http://mydomain.com/
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> NHibernate.AssertionFailure: collection was processed twice by flush()
   at NHibernate.Engine.Collections.PrepareCollectionForUpdate(IPersistentCollection collection, CollectionEntry entry, EntityMode entityMode, ISessionFactoryImplementor factory) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Engine\Collections.cs:line 164
   at NHibernate.Event.Default.FlushVisitor.ProcessCollection(Object collection, CollectionType type) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\FlushVisitor.cs:line 40
   at NHibernate.Event.Default.AbstractVisitor.ProcessEntityPropertyValues(Object[] values, IType[] types) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\AbstractVisitor.cs:line 116
   at NHibernate.Event.Default.AbstractFlushingEventListener.FlushEntities(FlushEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\AbstractFlushingEventListener.cs:line 161
   at NHibernate.Event.Default.AbstractFlushingEventListener.FlushEverythingToExecutions(FlushEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\AbstractFlushingEventListener.cs:line 61
   at NHibernate.Event.Default.DefaultAutoFlushEventListener.OnAutoFlush(AutoFlushEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\DefaultAutoFlushEventListener.cs:line 32
   at NHibernate.Impl.SessionImpl.AutoFlushIfRequired(ISet`1 querySpaces) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\SessionImpl.cs:line 1180
   at NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\SessionImpl.cs:line 1959
   at NHibernate.Impl.CriteriaImpl.List(IList results) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\CriteriaImpl.cs:line 265
   at NHibernate.Impl.CriteriaImpl.List[T]() in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\CriteriaImpl.cs:line 277
   at Orchard.ContentManagement.DefaultContentManager.GetManyImplementation(QueryHints hints, Action`2 predicate) in c:\Users\Josh\Documents\Orchard\orchard\src\Orchard\ContentManagement\DefaultContentManager.cs:line 359
   at Orchard.ContentManagement.DefaultContentManager.GetMany[T](IEnumerable`1 ids, VersionOptions options, QueryHints hints) in c:\Users\Josh\Documents\Orchard\orchard\src\Orchard\ContentManagement\DefaultContentManager.cs:line 276
   at Orchard.MediaLibrary.Handlers.MediaLibraryPickerFieldHandler.<>c__DisplayClass3.<InitilizeLoader>b__1()
   at System.Lazy`1.CreateValue()