Skip to content

Commit 109724f

Browse files
committed
Protect shared state in SessionFactoryObjectFactory.cs from concurrent modification. Fixes NH-3039.
1 parent 6348fd0 commit 109724f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/NHibernate/Impl/SessionFactoryObjectFactory.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using System.Collections;
2-
31
using System.Collections.Generic;
2+
using System.Runtime.CompilerServices;
3+
44

55
namespace NHibernate.Impl
66
{
@@ -39,6 +39,7 @@ static SessionFactoryObjectFactory()
3939
/// <param name="name">The name of the ISessionFactory.</param>
4040
/// <param name="instance">The ISessionFactory.</param>
4141
/// <param name="properties">The configured properties for the ISessionFactory.</param>
42+
[MethodImpl(MethodImplOptions.Synchronized)]
4243
public static void AddInstance(string uid, string name, ISessionFactory instance, IDictionary<string, string> properties)
4344
{
4445
if (log.IsDebugEnabled)
@@ -66,6 +67,7 @@ public static void AddInstance(string uid, string name, ISessionFactory instance
6667
/// <param name="uid">The identifier of the ISessionFactory.</param>
6768
/// <param name="name">The name of the ISessionFactory.</param>
6869
/// <param name="properties">The configured properties for the ISessionFactory.</param>
70+
[MethodImpl(MethodImplOptions.Synchronized)]
6971
public static void RemoveInstance(string uid, string name, IDictionary<string, string> properties)
7072
{
7173
if (!string.IsNullOrEmpty(name))
@@ -81,11 +83,12 @@ public static void RemoveInstance(string uid, string name, IDictionary<string, s
8183
/// </summary>
8284
/// <param name="name">The name of the ISessionFactory.</param>
8385
/// <returns>An instantiated ISessionFactory.</returns>
86+
[MethodImpl(MethodImplOptions.Synchronized)]
8487
public static ISessionFactory GetNamedInstance(string name)
8588
{
8689
log.Debug("lookup: name=" + name);
8790
ISessionFactory factory;
88-
bool found=NamedInstances.TryGetValue(name, out factory);
91+
bool found = NamedInstances.TryGetValue(name, out factory);
8992
if (!found)
9093
{
9194
log.Warn("Not found: " + name);
@@ -98,6 +101,7 @@ public static ISessionFactory GetNamedInstance(string name)
98101
/// </summary>
99102
/// <param name="uid">The identifier of the ISessionFactory.</param>
100103
/// <returns>An instantiated ISessionFactory.</returns>
104+
[MethodImpl(MethodImplOptions.Synchronized)]
101105
public static ISessionFactory GetInstance(string uid)
102106
{
103107
log.Debug("lookup: uid=" + uid);

0 commit comments

Comments
 (0)