Ошибка Nhibernate: BuidSessionFactory () Deadlock / Dropping Connection - PullRequest
0 голосов
/ 28 декабря 2010

Добрый день,

Я застрял в этой проблеме уже несколько дней, и я не чувствую, что мое понимание Nhibernate / SQL Server достаточно, чтобы я мог разобраться.

Проблема в том, что любой модульный тест, который включает в себя вызов:

Nhibernate.Cfg.Configuaration.BuildSessionFactory();

Просто застревает в рабочем состоянии, я вынужден нажать «Стоп», чтобы заставить NUnitреагировать.В этот момент появляется сообщение об ошибке со следующей информацией:

«Невозможно установить соединение, поскольку целевая машина активно отказала ему в этом» *

При «тексте исключения»;

    System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:51293

Server stack trace: 
   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
   at System.Runtime.Remoting.Channels.RemoteConnection.CreateNewSocket(EndPoint ipEndPoint)
   at System.Runtime.Remoting.Channels.RemoteConnection.CreateNewSocket()
   at System.Runtime.Remoting.Channels.SocketCache.GetSocket(String machinePortAndSid, Boolean openNew)
   at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.SendRequestWithRetry(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream)
   at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream)
   at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at NUnit.Core.TestRunner.get_Running()
   at NUnit.Core.ProxyTestRunner.get_Running()
   at NUnit.Util.TestLoader.get_Running()
   at NUnit.Gui.NUnitForm.get_IsTestRunning()
   at NUnit.Gui.NUnitForm.CancelRun()
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Мой NHibernate настроен так:

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="connection.connection_string">Server=MachineName\SQLEXPRESS;database=TestingDB;Integrated Security=true;</property>
    <property name ="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, Nhibernate.ByteCode.LinFu</property>
    <property name="show_sql">true</property>
  </session-factory>
</hibernate-configuration>

и с TestFixtureSetup вызывает следующее:

_configuration.Configure();
_configuration.AddAssembly(typeof(MyClass).Assembly);
_sessionFactory = _configuration.BuildSessionFactory();

Тест просто зависает в последней строке.Чтобы попытаться понять, что происходит не так, я включил log4net, который выдал следующий вывод при запуске теста.

[TestRunnerThread] INFO  NHibernate.Cfg.Environment - NHibernate 2.1.2.4000 (2.1.2.4000)
[TestRunnerThread] INFO  NHibernate.Cfg.Environment - hibernate-configuration section not found in application configuration file
[TestRunnerThread] INFO  NHibernate.Cfg.Environment - Bytecode provider name : lcg
[TestRunnerThread] INFO  NHibernate.Cfg.Environment - Using reflection optimizer
[TestRunnerThread] DEBUG NHibernate.Cfg.Configuration - connection.provider=NHibernate.Connection.DriverConnectionProvider
[TestRunnerThread] DEBUG NHibernate.Cfg.Configuration - dialect=NHibernate.Dialect.MsSql2008Dialect
[TestRunnerThread] DEBUG NHibernate.Cfg.Configuration - connection.driver_class=NHibernate.Driver.SqlClientDriver
[TestRunnerThread] DEBUG NHibernate.Cfg.Configuration - connection.connection_string=Server=MachineName\SQLEXPRESS;database=MySolution_Testing;Integrated Security=true;
[TestRunnerThread] DEBUG NHibernate.Cfg.Configuration - proxyfactory.factory_class=NHibernate.ByteCode.LinFu.ProxyFactoryFactory, Nhibernate.ByteCode.LinFu
[TestRunnerThread] DEBUG NHibernate.Cfg.Configuration - show_sql=true
[TestRunnerThread] DEBUG NHibernate.Cfg.Configuration - properties: System.Collections.Generic.Dictionary`2[System.String,System.String]
[TestRunnerThread] INFO  NHibernate.Cfg.Configuration - Mapping resource: MySolution.Models.Mappings.MenuItem.hbm.xml
[TestRunnerThread] INFO  NHibernate.Dialect.Dialect - Using dialect: NHibernate.Dialect.MsSql2008Dialect
[TestRunnerThread] INFO  NHibernate.Cfg.XmlHbmBinding.Binder - Mapping class: MySolution.Models.MenuItem -> MenuItems
[TestRunnerThread] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: ID -> MenuItemID, type: Int32
[TestRunnerThread] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: Name -> MenuItemName, type: String
[TestRunnerThread] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: ControllerName -> MenuItemController, type: String
[TestRunnerThread] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: ActionName -> MenuItemAction, type: String
[TestRunnerThread] INFO  NHibernate.Cfg.Configuration - Mapping resource: MySolution.Models.Mappings.Perspective.hbm.xml
[TestRunnerThread] INFO  NHibernate.Dialect.Dialect - Using dialect: NHibernate.Dialect.MsSql2008Dialect
[TestRunnerThread] INFO  NHibernate.Cfg.XmlHbmBinding.Binder - Mapping class: MySolution.Models.UserPerspective -> Perspectives
[TestRunnerThread] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: ID -> PerspectiveID, type: Int32
[TestRunnerThread] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: Name -> PerspectiveName, type: String
[TestRunnerThread] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: Description -> PerspectiveDescription, type: String
[TestRunnerThread] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: Password -> PerspectivePassword, type: String
[TestRunnerThread] INFO  NHibernate.Cfg.Configuration - Mapping resource: MySolution.Models.Mappings.ViewGroup.hbm.xml
[TestRunnerThread] INFO  NHibernate.Dialect.Dialect - Using dialect: NHibernate.Dialect.MsSql2008Dialect
[TestRunnerThread] INFO  NHibernate.Cfg.XmlHbmBinding.Binder - Mapping class: MySolution.Models.ViewGroup -> ViewGroups
[TestRunnerThread] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: ID -> ViewGroupID, type: Int32
[TestRunnerThread] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: Perspective -> Link_PerspectiveID, type: MySolution.Models.UserPerspective
[TestRunnerThread] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: MenuItems, type: Iesi.Collections.Generic.ISet`1[[MySolution.Models.MenuItem, MySolution.Models, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]](MySolution.Models.ViewGroup.MenuItems)
[TestRunnerThread] INFO  NHibernate.Cfg.Configuration - checking mappings queue
[TestRunnerThread] INFO  NHibernate.Cfg.Configuration - processing one-to-many association mappings
[TestRunnerThread] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Second pass for collection: MySolution.Models.ViewGroup.MenuItems
[TestRunnerThread] INFO  NHibernate.Cfg.XmlHbmBinding.Binder - mapping collection: MySolution.Models.ViewGroup.MenuItems -> MenuItems
[TestRunnerThread] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped collection key: MenuItemID, one-to-many: MySolution.Models.MenuItem
[TestRunnerThread] INFO  NHibernate.Cfg.Configuration - processing one-to-one association property references
[TestRunnerThread] INFO  NHibernate.Cfg.Configuration - processing foreign key constraints
[TestRunnerThread] DEBUG NHibernate.Cfg.Configuration - resolving reference to class: MySolution.Models.ViewGroup
[TestRunnerThread] DEBUG NHibernate.Cfg.Configuration - resolving reference to class: MySolution.Models.UserPerspective
[TestRunnerThread] INFO  NHibernate.Cfg.Configuration - processing filters (second pass)
[TestRunnerThread] INFO  NHibernate.Dialect.Dialect - Using dialect: NHibernate.Dialect.MsSql2008Dialect
[TestRunnerThread] INFO  NHibernate.Exceptions.SQLExceptionConverterFactory - Using dialect defined converter
[TestRunnerThread] INFO  NHibernate.Cfg.SettingsFactory - Generate SQL with comments: disabled
[TestRunnerThread] INFO  NHibernate.Connection.ConnectionProviderFactory - Initializing connection provider: NHibernate.Connection.DriverConnectionProvider
[TestRunnerThread] INFO  NHibernate.Connection.ConnectionProvider - Configuring ConnectionProvider
[TestRunnerThread] INFO  NHibernate.Cfg.SettingsFactory - Transaction factory: NHibernate.Transaction.AdoNetWithDistrubtedTransactionFactory
[TestRunnerThread] INFO  NHibernate.Cfg.SettingsFactory - Optimize cache for minimal puts: False
[TestRunnerThread] INFO  NHibernate.Cfg.SettingsFactory - Connection release mode: auto
[TestRunnerThread] INFO  NHibernate.Cfg.SettingsFactory - Default batch fetch size: 1
[TestRunnerThread] INFO  NHibernate.Cfg.SettingsFactory - echoing all SQL to stdout
[TestRunnerThread] INFO  NHibernate.Cfg.SettingsFactory - Statistics: disabled
[TestRunnerThread] INFO  NHibernate.Cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
[TestRunnerThread] INFO  NHibernate.Cfg.SettingsFactory - Query translator: NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory
[TestRunnerThread] INFO  NHibernate.Cfg.SettingsFactory - Query language substitutions: {}
[TestRunnerThread] INFO  NHibernate.Cfg.SettingsFactory - cache provider: NHibernate.Cache.NoCacheProvider, NHibernate, Version=2.1.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4
[TestRunnerThread] DEBUG NHibernate.Cfg.SettingsFactory - Wrap result sets: disabled
[TestRunnerThread] INFO  NHibernate.Cfg.SettingsFactory - Batcher factory: NHibernate.AdoNet.NonBatchingBatcherFactory, NHibernate, Version=2.1.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4
[TestRunnerThread] INFO  NHibernate.Cfg.SettingsFactory - Default entity-mode: Poco
[TestRunnerThread] INFO  NHibernate.Cfg.SettingsFactory - Named query checking : enabled
[TestRunnerThread] INFO  NHibernate.Impl.SessionFactoryImpl - building session factory
[TestRunnerThread] DEBUG NHibernate.Impl.SessionFactoryImpl - Session factory constructed with filter configurations : {}
[TestRunnerThread] DEBUG NHibernate.Impl.SessionFactoryImpl - instantiating session factory with properties: {'use_reflection_optimizer'='True', 'connection.provider'='NHibernate.Connection.DriverConnectionProvider', 'dialect'='NHibernate.Dialect.MsSql2008Dialect', 'connection.driver_class'='NHibernate.Driver.SqlClientDriver', 'connection.connection_string'='Server=MachineName\SQLEXPRESS;database=MySolution_Testing;Integrated Security=true;', 'proxyfactory.factory_class'='NHibernate.ByteCode.LinFu.ProxyFactoryFactory, Nhibernate.ByteCode.LinFu', 'show_sql'='true'}
[TestRunnerThread] DEBUG NHibernate.Connection.DriverConnectionProvider - Obtaining IDbConnection from Driver
[TestRunnerThread] DEBUG NHibernate.Connection.ConnectionProvider - Closing connection

Как вы можете видеть, NHibernate, кажется, сам конфигурируется правильно, однако последние две строкиКажется, предположить, что когда на самом деле запрашивается соединение, что-то выдает ошибку и все закрывается.Об этом не сообщается NUnit, и поэтому он просто ждет, пока не будет установлено действующее соединение.

У меня есть другие проекты, которые используют конфигурацию Fluent, которая, кажется, работает правильно, но эти старые проекты используют базу данных SQL Compact, а не SQL Express.

Кто-нибудь может предложить решение этой проблемы??

Спасибо, что уделили время.

1 Ответ

0 голосов
/ 05 сентября 2011

Наиболее вероятной причиной этого является переполнение стека, которое приводит к сбою процесса nunit-agent.exe.Это приводит к тому, что исполнитель теста nunit.exe теряет связь с процессом агента.См. NUnit сбой с NHibernate для получения дополнительной информации.

Я знаю, что это почти год, но, надеюсь, вы или кто-то еще может найти это полезным.

...