Set the agent in transit teleport flag at the first available opportunity (i.e. when IsInTransit() was being checked) to close down a race condition.

On EntityTransferModule.DoTeleport() there was an IsInTransit() check to prevent multiple simultaneous teleport attempts.
However, the SetInTransit() was only performed later on, which left a window in which multiple threads could pass the IsInTransit() check.
This has been seen in the field and the results aren't pretty.
This commit effectively combines the IsInTransit() and SetInTransit() checks so there is no such window.
More failure cases are made to to call ResetInTransit() to adjust to this move.
0.7.4.1
Justin Clark-Casey (justincc) 2012-05-14 18:36:26 +01:00
parent 42557d7d4c
commit c2aa3b90d9
1 changed files with 40 additions and 14 deletions

View File

@ -210,6 +210,9 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
sp.Name, sp.AbsolutePosition, sp.Scene.RegionInfo.RegionName, position, destinationRegionName,
e.Message, e.StackTrace);
// Make sure that we clear the in-transit flag so that future teleport attempts don't always fail.
ResetFromTransit(sp.UUID);
sp.ControllingClient.SendTeleportFailed("Internal error");
}
}
@ -384,7 +387,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
return;
}
if (IsInTransit(sp.UUID)) // Avie is already on the way. Caller shouldn't do this.
if (!SetInTransit(sp.UUID)) // Avie is already on the way. Caller shouldn't do this.
{
m_log.DebugFormat(
"[ENTITY TRANSFER MODULE]: Ignoring teleport request of {0} {1} to {2} ({3}) {4}/{5} - agent is already in transit.",
@ -432,8 +435,11 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
if (!m_aScene.SimulationService.QueryAccess(finalDestination, sp.ControllingClient.AgentId, Vector3.Zero, out version, out reason))
{
sp.ControllingClient.SendTeleportFailed("Teleport failed: " + reason);
ResetFromTransit(sp.UUID);
return;
}
m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Destination is running version {0}", version);
sp.ControllingClient.SendTeleportStart(teleportFlags);
@ -473,13 +479,16 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
bool logout = false;
if (!CreateAgent(sp, reg, finalDestination, agentCircuit, teleportFlags, out reason, out logout))
{
sp.ControllingClient.SendTeleportFailed(String.Format("Teleport refused: {0}",
reason));
sp.ControllingClient.SendTeleportFailed(
String.Format("Teleport refused: {0}", reason));
ResetFromTransit(sp.UUID);
return;
}
// OK, it got this agent. Let's close some child agents
sp.CloseChildAgents(newRegionX, newRegionY);
IClientIPEndpoint ipepClient;
if (NeedsNewAgent(sp.DrawDistance, oldRegionX, newRegionX, oldRegionY, newRegionY))
{
@ -516,8 +525,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
capsPath = finalDestination.ServerURI + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath);
}
SetInTransit(sp.UUID);
// Let's send a full update of the agent. This is a synchronous call.
AgentData agent = new AgentData();
sp.CopyTo(agent);
@ -1956,25 +1963,43 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
return count > 0;
}
protected void SetInTransit(UUID id)
/// <summary>
/// Set that an agent is in the process of being teleported.
/// </summary>
/// <param name='id'>The ID of the agent being teleported</param>
/// <returns>true if the agent was not already in transit, false if it was</returns>
protected bool SetInTransit(UUID id)
{
lock (m_agentsInTransit)
{
if (!m_agentsInTransit.Contains(id))
{
m_agentsInTransit.Add(id);
return true;
}
}
protected bool IsInTransit(UUID id)
{
lock (m_agentsInTransit)
{
if (m_agentsInTransit.Contains(id))
return true;
}
return false;
}
/// <summary>
/// Show whether the given agent is being teleported.
/// </summary>
/// <returns>true if the agent is in the process of being teleported, false otherwise.</returns>
/// <param name='id'>The agent ID</para></param>
protected bool IsInTransit(UUID id)
{
lock (m_agentsInTransit)
return m_agentsInTransit.Contains(id);
}
/// <summary>
/// Set that an agent is no longer being teleported.
/// </summary>
/// <returns></returns>
/// <param name='id'>
/// true if the agent was flagged as being teleported when this method was called, false otherwise
/// </param>
protected bool ResetFromTransit(UUID id)
{
lock (m_agentsInTransit)
@ -1985,6 +2010,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
return true;
}
}
return false;
}