Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AsyncReadWriterLock issue still persists #3026

Closed
mohitchugh89 opened this issue Feb 22, 2022 · 9 comments
Closed

AsyncReadWriterLock issue still persists #3026

mohitchugh89 opened this issue Feb 22, 2022 · 9 comments

Comments

@mohitchugh89
Copy link

Cannot access a disposed name: 'AsyncReaderWriterLock'

NHibernate.Util.AsyncReaderWriterLockAssertNotDisposed()\r\n at NHibernate.Util. SystemException
waitForReadLocks)\r\n at at NHibernate.C
an at NHibernate.Engine.TwoPhaseLoad.lnitializeEntity(Object entity, Boolean readOnly, ISessionlmplementor session, PreLoadEvent preLoadEvent, PostLoadEvent postLoadEvent, Action'2 at
in, Boolean readOnly, CacheBatcher cacheBatcher)\r\n at NHibernate.Loader.Loader.DoQuery(lSessionlmplementor session, QueryParameters queryParameters, Boolean returnProxies, IResultTransformer forcedResultTransformer, QueryCac

@mohitchugh89
Copy link
Author

Created New issue AsyncReadWriterLock issue still persists #3026

@fredericDelaporte
Copy link
Member

Your report is garbled and quite minimal, it is hard to investigate on this.

Can you provide a full, non corrupted stack trace? Can you also provide an example code allowing to reproduce the trouble? See here for more instructions on how to effectively report a bug.

@mohitchugh89
Copy link
Author

exc.InnerException.StackTrace
at NHibernate.Util.AsyncReaderWriterLock.AssertNotDisposed()
at NHibernate.Util.AsyncReaderWriterLock.CanEnterReadLock(SemaphoreSlim& waitingReadLockSemaphore)
at NHibernate.Util.AsyncReaderWriterLock.ReadLock()
at NHibernate.Util.AsyncReaderWriterLock.NHibernate.Cache.ICacheLock.ReadLock()
at NHibernate.Cache.ReadWriteCache.Get(CacheKey key, Int64 txTimestamp)
at NHibernate.Event.Default.DefaultLoadEventListener.LoadFromSecondLevelCache(LoadEvent event, IEntityPersister persister, LoadType options)
at NHibernate.Event.Default.DefaultLoadEventListener.DoLoad(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options)
at NHibernate.Event.Default.DefaultLoadEventListener.Load(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options)
at NHibernate.Event.Default.DefaultLoadEventListener.ProxyOrLoad(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options)
at NHibernate.Event.Default.DefaultLoadEventListener.OnLoad(LoadEvent event, LoadType loadType)
at NHibernate.Impl.SessionImpl.FireLoad(LoadEvent event, LoadType loadType)
at NHibernate.Impl.SessionImpl.InternalLoad(String entityName, Object id, Boolean eager, Boolean isNullable)
at NHibernate.Type.EntityType.ResolveIdentifier(Object id, ISessionImplementor session)
at NHibernate.Engine.TwoPhaseLoad.InitializeEntity(Object entity, Boolean readOnly, ISessionImplementor session, PreLoadEvent preLoadEvent, PostLoadEvent postLoadEvent, Action`2 cacheBatchingHandler)
at NHibernate.Loader.Loader.InitializeEntitiesAndCollections(IList hydratedObjects, DbDataReader reader, ISessionImplementor session, Boolean readOnly, CacheBatcher cacheBatcher)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies, IResultTransformer forcedResultTransformer, QueryCacheResultBuilder queryCacheResultBuilder)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies, IResultTransformer forcedResultTransformer, QueryCacheResultBuilder queryCacheResultBuilder)
at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters, IResultTransformer forcedResultTransformer, QueryCacheResultBuilder queryCacheResultBuilder)

@iurijacob
Copy link

iurijacob commented Mar 16, 2022

Same here. It´s happening in the context of our automated API tests after we've upgraded NHibernate from version 5.2.7 to 5.3.11. Every call to our api runs in a unit of work, which in turn opens a new session and starts a transaction. Our test suit uses SQLiteConfiguration for InMemory database, while our running instance (which actually is working fine) uses MsSqlConfiguration.MsSql2012. This seems to be the only difference between them.

The weird thing is that some tests works and some don't. If I run the failing tests individually, they succeed. I still haven't found why this happens.

For now I'll downgrade it back to version 5.2.7.

Hope this information helps you in some way.

The exception stacktrace:

   at NHibernate.Util.AsyncReaderWriterLock.AssertNotDisposed()
   at NHibernate.Util.AsyncReaderWriterLock.CanEnterReadLock(SemaphoreSlim& waitingReadLockSemaphore)
   at NHibernate.Util.AsyncReaderWriterLock.ReadLock()
   at NHibernate.Util.AsyncReaderWriterLock.NHibernate.Cache.ICacheLock.ReadLock()
   at NHibernate.Cache.ReadWriteCache.Get(CacheKey key, Int64 txTimestamp)
   at NHibernate.Event.Default.DefaultLoadEventListener.LoadFromSecondLevelCache(LoadEvent event, IEntityPersister persister, LoadType options)
   at NHibernate.Event.Default.DefaultLoadEventListener.DoLoad(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options)
   at NHibernate.Event.Default.DefaultLoadEventListener.Load(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options)
   at NHibernate.Event.Default.DefaultLoadEventListener.ProxyOrLoad(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options)
   at NHibernate.Event.Default.DefaultLoadEventListener.OnLoad(LoadEvent event, LoadType loadType)
   at NHibernate.Impl.SessionImpl.FireLoad(LoadEvent event, LoadType loadType)
   at NHibernate.Impl.SessionImpl.Get(String entityName, Object id)
   at NHibernate.Impl.SessionImpl.Get(Type entityClass, Object id)
   at NHibernate.Impl.SessionImpl.Get[T](Object id)
   at ...

@mmehanosh
Copy link

mmehanosh commented Jun 8, 2022

I had a similar exception in unit tests on NHibernate 5.3.11
and no exception on version 5.2.7. But after an investigation I found that ISessionFactory was used after disposing. Code sample (for 5.3.11) follows:

                ISessionFactory sf = ... //got a good factory
                sf.Dispose(); //disposed accidentally
                var ses = sf.OpenSession(); //no clue? It works!
                //even the property ses.IsConnected is true!
                ses.Get<MyEntity>(0); // but an exception is thrown here

Exception:

System.ObjectDisposedException: Доступ к ликвидированному объекту невозможен.
Имя объекта: "AsyncReaderWriterLock".
в NHibernate.Util.AsyncReaderWriterLock.AssertNotDisposed()
в NHibernate.Util.AsyncReaderWriterLock.CanEnterReadLock(SemaphoreSlim& waitingReadLockSemaphore)
в NHibernate.Util.AsyncReaderWriterLock.ReadLock()
в NHibernate.Util.AsyncReaderWriterLock.NHibernate.Cache.ICacheLock.ReadLock()
в NHibernate.Cache.ReadWriteCache.Get(CacheKey key, Int64 txTimestamp)
в NHibernate.Event.Default.DefaultLoadEventListener.LoadFromSecondLevelCache(LoadEvent event, IEntityPersister persister, LoadType options)
в NHibernate.Event.Default.DefaultLoadEventListener.DoLoad(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options)
в NHibernate.Event.Default.DefaultLoadEventListener.Load(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options)
в NHibernate.Event.Default.DefaultLoadEventListener.ProxyOrLoad(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options)
в NHibernate.Event.Default.DefaultLoadEventListener.OnLoad(LoadEvent event, LoadType loadType)
в NHibernate.Impl.SessionImpl.FireLoad(LoadEvent event, LoadType loadType)
в NHibernate.Impl.SessionImpl.Get(String entityName, Object id)
в NHibernate.Impl.SessionImpl.Get[T](Object id)

@fredericDelaporte
Copy link
Member

So, we should add a check raising DisposedException when opening a session from a disposed session factory. It may help pinpoint the bug in user code.

fredericDelaporte added a commit to fredericDelaporte/nhibernate-core that referenced this issue Aug 21, 2022
fredericDelaporte added a commit to fredericDelaporte/nhibernate-core that referenced this issue Aug 21, 2022
fredericDelaporte added a commit to fredericDelaporte/nhibernate-core that referenced this issue Aug 21, 2022
hazzik pushed a commit that referenced this issue Aug 23, 2022
This would enable to help diagnose #3026 complaints
@fredericDelaporte
Copy link
Member

May you check with latest 5.3.x MyGet build to check if you have still that same error?

@mohitchugh89
Copy link
Author

mohitchugh89 commented Aug 25, 2022 via email

@hazzik
Copy link
Member

hazzik commented Jul 31, 2023

I would assume that this is not an issue anymore, @iurijacob, @mohitchugh89, @mmehanosh.

Let me know if you still see this issue, and I will reopen if needed.

@hazzik hazzik closed this as not planned Won't fix, can't repro, duplicate, stale Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants