Skip to content

Commit ef106af

Browse files
committed
Fixed a thread safety issue in BsonClassMap.
1 parent e07c637 commit ef106af

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/MongoDB.Bson/Serialization/BsonClassMap.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,15 @@ public static Type GetMemberInfoType(MemberInfo memberInfo)
295295
/// <returns>All registered class maps.</returns>
296296
public static IEnumerable<BsonClassMap> GetRegisteredClassMaps()
297297
{
298-
return __classMaps.Values;
298+
BsonSerializer.ConfigLock.EnterReadLock();
299+
try
300+
{
301+
return __classMaps.Values.ToList(); // return a copy for thread safety
302+
}
303+
finally
304+
{
305+
BsonSerializer.ConfigLock.ExitReadLock();
306+
}
299307
}
300308

301309
/// <summary>

0 commit comments

Comments
 (0)