tags:

views:

119

answers:

0

I have a suite of integration tests that run on top of my NHibernate 2.1 DAL. Recently, our CI server has been reporting intermittent test failures such as:

  • System.InvalidOperationException: ExecuteNonQuery requires an open and available Connection. The connection's current state is open

  • System.InvalidOperationException: Invalid attempt to call Read when reader is closed

The errors are intermittent, but if they occur they always occur in exactly the same test, at exactly the same place. The test fails inside some setup code that:

  1. Opens a new ISession and binds it to the CurrentSessionContext, using thread_static.
  2. Builds up a complex object graph of a root entity and some associated children
  3. Attempts to save, flush, and evict the object from the session. Fails during Save()

The error always occurs at the same place, indicating there's something specific to this test causing the problem. But the failure is intermittent, has only been observed on the CI server [a VM under VMWare], and none of the other tests that use the same setup pattern have a problem.

Any troubleshooting suggestions?

What I've checked so far:

  • Rebooting the CI server did not help
  • I'm not doing anything to the ISession's connection object

Sample stack trace of the error:

System.InvalidOperationException : ExecuteNonQuery requires an open and available Connection. The connection's current state is open.at System.Data.SqlClient.SqlConnection.GetOpenConnection(String method)
at System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(String method, SqlCommand command)
at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd)
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql, Object obj, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object[] fields, Object obj, ISessionImplementor session)
at NHibernate.Action.EntityIdentityInsertAction.Execute()
at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
at NHibernate.Event.Default.AbstractSaveEventListener.PerformSaveOrReplicate(Object entity, EntityKey key, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)
at NHibernate.Event.Default.AbstractSaveEventListener.PerformSave(Object entity, Object id, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)
at NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object entity, String entityName, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)
at NHibernate.Event.Default.DefaultSaveEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent event)
at NHibernate.Event.Default.DefaultSaveEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event)
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event)
at NHibernate.Impl.SessionImpl.FireSave(SaveOrUpdateEvent event)
at NHibernate.Impl.SessionImpl.Save(Object obj)
at OneOfMyTestSetupMethods()