Issues

Select view

Select search mode

 
28 of 28

Found the unexpected error Probable I/O race condition detected while copying memory

Cannot Reproduce

Description

I'm using NH 4.1.0. I'm unable to reproduce the error: it seems to happen randomly, having show_sql set to true I get an exception that deadlock the application:

2017-08-25 18:48:29,034 [ERROR] [AdvancedTransport] Mfs.Business.Transportation.BaseOrder - FilterMovementsByDestinationFunctionalArea: found the unexpected error Probable I/O race condition detected while copying memory. The I/O package is not thread safe by default. In multithreaded applications, a stream must be accessed in a thread-safe way, such as a thread-safe wrapper returned by TextReader's or TextWriter's Synchronized methods. This also applies to classes like StreamWriter and StreamReader. NHibernate.Exceptions.GenericADOException: could not initialize a collection: [Mfs.Domain.TransportManager.TransportUnit.TransportUnitProperties#100100006479][SQL: SELECT transportu0_."FK_TRANSPORT_UNIT" as FK3_1_, transportu0_."PK_ID" as PK1_1_, transportu0_."PK_ID" as PK1_36_0_, transportu0_.Version as Version36_0_, transportu0_."FK_TRANSPORT_UNIT" as FK3_36_0_, transportu0_."PROPERTY_KEY" as PROPERTY4_36_0_, transportu0_."PROPERTY_VALUE" as PROPERTY5_36_0_, transportu0_."PROPERTY_NOTIFIED" as PROPERTY6_36_0_, transportu0_."PROPERTY_REQUIRED" as PROPERTY7_36_0_, transportu0_."PROPERTY_SUCCESS" as PROPERTY8_36_0_ FROM "MFS$TRANSPORT_UNIT_PROPERTY" transportu0_ WHERE transportu0_."FK_TRANSPORT_UNIT"=?] ---> System.IndexOutOfRangeException: Probable I/O race condition detected while copying memory. The I/O package is not thread safe by default. In multithreaded applications, a stream must be accessed in a thread-safe way, such as a thread-safe wrapper returned by TextReader's or TextWriter's Synchronized methods. This also applies to classes like StreamWriter and StreamReader. at System.Buffer.InternalBlockCopy(Array src, Int32 srcOffsetBytes, Array dst, Int32 dstOffsetBytes, Int32 byteCount) at System.IO.StreamWriter.Write(Char[] buffer, Int32 index, Int32 count) at System.IO.TextWriter.SyncTextWriter.WriteLine(String value) at NHibernate.AdoNet.Util.SqlStatementLogger.LogCommand(String message, IDbCommand command, FormatStyle style) at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd) at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session) at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies, IResultTransformer forcedResultTransformer) at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies, IResultTransformer forcedResultTransformer) at NHibernate.Loader.Loader.LoadCollection(ISessionImplementor session, Object id, IType type) --- End of inner exception stack trace --- at NHibernate.Loader.Loader.LoadCollection(ISessionImplementor session, Object id, IType type) at NHibernate.Event.Default.DefaultInitializeCollectionEventListener.OnInitializeCollection(InitializeCollectionEvent event) at NHibernate.Impl.SessionImpl.InitializeCollection(IPersistentCollection collection, Boolean writing) at NHibernate.Collection.AbstractPersistentCollection.ForceInitialization() at NHibernate.Engine.StatefulPersistenceContext.InitializeNonLazyCollections() at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies, IResultTransformer forcedResultTransformer) at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object id, IType identifierType, Object optionalObject, String optionalEntityName, Object optionalIdentifier, IEntityPersister persister) at NHibernate.Loader.Entity.AbstractEntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject, Object optionalId) at NHibernate.Loader.Entity.AbstractEntityLoader.Load(Object id, Object optionalObject, ISessionImplementor session) at NHibernate.Event.Default.DefaultLoadEventListener.LoadFromDatasource(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.OnLoad(LoadEvent event, LoadType loadType) at NHibernate.Impl.SessionImpl.FireLoad(LoadEvent event, LoadType loadType) at NHibernate.Impl.SessionImpl.ImmediateLoad(String entityName, Object id) at NHibernate.Proxy.AbstractLazyInitializer.Initialize() at NHibernate.Proxy.DefaultLazyInitializer.Intercept(InvocationInfo info) at TransportUnitProxy.get_PhysicalId()

Environment

Windows Server 2012 R2

Details

Assignee

Reporter

Labels

Components

Affects versions

Priority

Who's Looking?

Open Who's Looking?
Created August 28, 2017 at 6:01 AM
Updated October 22, 2018 at 9:05 AM
Resolved October 22, 2018 at 9:04 AM

Activity

Show:

Frédéric DelaporteOctober 22, 2018 at 9:05 AM

Moved here.

For this issue to happen, and as the error message implies itself, it seems likely to me the session has ended-up shared among many threads, which is not supported. The session is not thread safe and must be used by a single thread. This includes implicit usages due to proxy initialization. (For example, when accessing an association, by default it is loaded on demand.)

Please add on the above linked GitHub issue any additional elements which would help reproducing the trouble if it can be done without a multi-threaded usage of a session.

Who's Looking?