Skip to content

Commit a31c36e

Browse files
committed
Move unsetting _childSession to Close method. Add tests. To be squashed.
1 parent b24a75a commit a31c36e

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/NHibernate.Test/NHSpecificTest/NH3985/Fixture.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,20 @@ public void GetChildSession_ShouldReturnNonDisposedInstance()
2424
}
2525
}
2626
}
27+
28+
[Test]
29+
public void GetChildSession_ShouldReturnNonClosedInstance()
30+
{
31+
using (var rootSession = OpenSession())
32+
{
33+
var childSession1 = rootSession.GetChildSession();
34+
childSession1.Close();
35+
36+
using (var childSession2 = rootSession.GetChildSession())
37+
{
38+
Assert.DoesNotThrow(() => { childSession2.Get<Process>(Guid.NewGuid()); });
39+
}
40+
}
41+
}
2742
}
2843
}

src/NHibernate/Impl/SessionImpl.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Linq.Expressions;
77
using System.Runtime.Serialization;
88
using System.Security;
9-
using System.Threading;
109
using NHibernate.AdoNet;
1110
using NHibernate.Collection;
1211
using NHibernate.Criterion;
@@ -382,6 +381,7 @@ public DbConnection Close()
382381
{
383382
SetClosed();
384383
Cleanup();
384+
if (rootSession != null) rootSession._childSession = null;
385385
}
386386
}
387387
}
@@ -1683,8 +1683,6 @@ private void Dispose(bool isDisposing)
16831683

16841684
IsAlreadyDisposed = true;
16851685

1686-
rootSession?.RemoveChildSession(this);
1687-
16881686
// nothing for Finalizer to do - so tell the GC to ignore it
16891687
GC.SuppressFinalize(this);
16901688
}
@@ -2608,10 +2606,5 @@ public override IEntityPersister GetEntityPersister(string entityName, object ob
26082606
}
26092607
}
26102608
}
2611-
2612-
void RemoveChildSession(ISession session)
2613-
{
2614-
Interlocked.CompareExchange(ref _childSession, null, session);
2615-
}
26162609
}
26172610
}

0 commit comments

Comments
 (0)