From 4dc8e7e0f8f0165fc242802864f39d9aab2f72d3 Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Sun, 21 Oct 2007 22:53:54 +0000 Subject: [PATCH] * Added a lock to the user profile cache to prevent simultaneous duplicate additions to the database. (Attempting to fix bug reported by nebadon) --- .../Communications/Cache/UserProfileCache.cs | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/OpenSim/Framework/Communications/Cache/UserProfileCache.cs b/OpenSim/Framework/Communications/Cache/UserProfileCache.cs index 9e32ea5360..362ab176c7 100644 --- a/OpenSim/Framework/Communications/Cache/UserProfileCache.cs +++ b/OpenSim/Framework/Communications/Cache/UserProfileCache.cs @@ -59,18 +59,22 @@ namespace OpenSim.Framework.Communications.Caches /// public void AddNewUser(LLUUID userID) { - if (!this.UserProfiles.ContainsKey(userID)) + // Potential fix - Multithreading issue. + lock (UserProfiles) { - CachedUserInfo userInfo = new CachedUserInfo(this.m_parent); - userInfo.UserProfile = this.RequestUserProfileForUser(userID); - if (userInfo.UserProfile != null) + if (!this.UserProfiles.ContainsKey(userID)) { - this.RequestInventoryForUser(userID, userInfo); - this.UserProfiles.Add(userID, userInfo); - } - else - { - System.Console.WriteLine("CACHE", "User profile for user not found"); + CachedUserInfo userInfo = new CachedUserInfo(this.m_parent); + userInfo.UserProfile = this.RequestUserProfileForUser(userID); + if (userInfo.UserProfile != null) + { + this.RequestInventoryForUser(userID, userInfo); + this.UserProfiles.Add(userID, userInfo); + } + else + { + System.Console.WriteLine("CACHE", "User profile for user not found"); + } } } }