Skip to content

NH-3985 - Bugfix for subsequent child sessions being returned in disposed state #600

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

Merged
merged 1 commit into from
Apr 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3985/Entity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace NHibernate.Test.NHSpecificTest.NH3985
{
public partial class Process
{
public virtual Guid ProcessID { get; set; }
public virtual string Name { get; set; }
}
}
43 changes: 43 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3985/Fixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using NUnit.Framework;
using System;

namespace NHibernate.Test.NHSpecificTest.NH3985
{
/// <summary>
/// The test verifies that subsequent child sessions are not issued in already-disposed state.
/// </summary>
[TestFixture]
public class Fixture : BugTestCase
{
[Test]
public void GetChildSession_ShouldReturnNonDisposedInstance()
{
using (var rootSession = OpenSession())
{
using (var childSession1 = rootSession.GetChildSession())
{
}

using (var childSession2 = rootSession.GetChildSession())
{
Assert.DoesNotThrow(() => { childSession2.Get<Process>(Guid.NewGuid()); });
}
}
}

[Test]
public void GetChildSession_ShouldReturnNonClosedInstance()
{
using (var rootSession = OpenSession())
{
var childSession1 = rootSession.GetChildSession();
childSession1.Close();

using (var childSession2 = rootSession.GetChildSession())
{
Assert.DoesNotThrow(() => { childSession2.Get<Process>(Guid.NewGuid()); });
}
}
}
}
}
7 changes: 7 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3985/Mappings.hbm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" namespace="NHibernate.Test.NHSpecificTest.NH3985">
<class name="Process">
<id name="ProcessID" generator="guid.comb" />
<property name="Name" />
</class>
</hibernate-mapping>
3 changes: 3 additions & 0 deletions src/NHibernate.Test/NHibernate.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,8 @@
<Compile Include="NHSpecificTest\EntityWithUserTypeCanHaveLinqGenerators\IExample.cs" />
<Compile Include="Insertordering\NH3931Entities.cs" />
<Compile Include="NHSpecificTest\NH1904\StructFixture.cs" />
<Compile Include="NHSpecificTest\NH3985\Entity.cs" />
<Compile Include="NHSpecificTest\NH3985\Fixture.cs" />
<Compile Include="NHSpecificTest\NH3247\Entity.cs" />
<Compile Include="NHSpecificTest\NH3247\Fixture.cs" />
<Compile Include="NHSpecificTest\NH3386\Entity.cs" />
Expand Down Expand Up @@ -2668,6 +2670,7 @@
<EmbeddedResource Include="NHSpecificTest\NH2195\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH3187\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH3932\Model\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH3985\Mappings.hbm.xml" />
<EmbeddedResource Include="TypedManyToOne\Customer.hbm.xml" />
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion src/NHibernate/Impl/SessionImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public sealed class SessionImpl : AbstractSessionImpl, IEventSource, ISerializab
private readonly StatefulPersistenceContext persistenceContext;

[NonSerialized]
private readonly ISession rootSession;
private readonly SessionImpl rootSession;

[NonSerialized]
ISession _childSession;
Expand Down Expand Up @@ -381,6 +381,7 @@ public DbConnection Close()
{
SetClosed();
Cleanup();
if (rootSession != null) rootSession._childSession = null;
}
}
}
Expand Down Expand Up @@ -1681,6 +1682,7 @@ private void Dispose(bool isDisposing)
// free unmanaged resources here

IsAlreadyDisposed = true;

// nothing for Finalizer to do - so tell the GC to ignore it
GC.SuppressFinalize(this);
}
Expand Down