diff --git a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs index 8c84c9807a..8238e23f9c 100644 --- a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs +++ b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs @@ -222,7 +222,12 @@ namespace OpenSim.Region.Framework.Scenes public void SendCloseChildAgentConnections(UUID agentID, List regionslst) { foreach (ulong handle in regionslst) - Util.FireAndForget(delegate { SendCloseChildAgent(agentID, handle); }); + { + // We must take a copy here since handle is acts like a reference when used in an iterator. + // This leads to race conditions if directly passed to SendCloseChildAgent with more than one neighbour region. + ulong handleCopy = handle; + Util.FireAndForget((o) => { SendCloseChildAgent(agentID, handleCopy); }); + } } public List RequestNamedRegions(string name, int maxNumber)