Set IClientAPI.IsActive = false early on client removal due to ack timeout rather than using IsLoggingOut flag.

IsActive is more appropriate since unack timeout is not due to voluntary logout.
This is in line with operations such as manual kick that do not set the IsLoggingOut flag.
It's also slightly better race-wise since it reduces the chance of this operation clashing with another reason for client deactivation (e.g. manual kick).
0.7.4.1
Justin Clark-Casey (justincc) 2012-06-12 02:16:36 +01:00
parent c89db34fc4
commit b099f26376
2 changed files with 37 additions and 34 deletions

View File

@ -741,22 +741,19 @@ namespace OpenSim.Framework
string Name { get; } string Name { get; }
/// <summary> /// <summary>
/// True if the client is active (sending and receiving new UDP messages). False if the client is closing. /// True if the client is active (sending and receiving new UDP messages). False if the client is being closed.
/// </summary> /// </summary>
bool IsActive { get; set; } bool IsActive { get; set; }
/// <summary> /// <summary>
/// Set if the client is closing due to a logout request or because of too much time since last ack. /// Set if the client is closing due to a logout request
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// Do not use this flag if you want to know if the client is closing, since it will not be set in other /// Do not use this flag if you want to know if the client is closing, since it will not be set in other
/// circumstances (e.g. if a child agent is closed or the agent is kicked off the simulator). Use IsActive /// circumstances (e.g. if a child agent is closed or the agent is kicked off the simulator). Use IsActive
/// instead. /// instead with a IClientAPI.SceneAgent.IsChildAgent check if necessary.
/// ///
/// Only set for root agents. /// Only set for root agents.
///
/// TODO: Too much time since last ack should probably be a separate property, or possibly part of a state
/// machine.
/// </remarks> /// </remarks>
bool IsLoggingOut { get; set; } bool IsLoggingOut { get; set; }

View File

@ -555,15 +555,17 @@ namespace OpenSim.Region.ClientStack.LindenUDP
if (udpClient.IsPaused) if (udpClient.IsPaused)
timeoutTicks = m_pausedAckTimeout; timeoutTicks = m_pausedAckTimeout;
if (!client.IsLoggingOut && if (client.IsActive &&
(Environment.TickCount & Int32.MaxValue) - udpClient.TickLastPacketReceived > timeoutTicks) (Environment.TickCount & Int32.MaxValue) - udpClient.TickLastPacketReceived > timeoutTicks)
{ {
m_log.WarnFormat( // We must set IsActive synchronously so that we can stop the packet loop reinvoking this method, even
"[LLUDPSERVER]: Ack timeout for {0} {1}, disconnecting", // though it's set later on by LLClientView.Close()
client.Name, client.AgentId); client.IsActive = false;
StatsManager.SimExtraStats.AddAbnormalClientThreadTermination(); // Fire this out on a different thread so that we don't hold up outgoing packet processing for
LogoutClientDueToTimeout(client); // everybody else if this is being called due to an ack timeout.
// This is the same as processing as the async process of a logout request.
Util.FireAndForget(o => DeactivateClientDueToTimeout(client));
return; return;
} }
@ -792,7 +794,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
Interlocked.Increment(ref udpClient.PacketsReceived); Interlocked.Increment(ref udpClient.PacketsReceived);
int now = Environment.TickCount & Int32.MaxValue; int now = Environment.TickCount & Int32.MaxValue;
udpClient.TickLastPacketReceived = now; // udpClient.TickLastPacketReceived = now;
#region ACK Receiving #region ACK Receiving
@ -1113,30 +1115,30 @@ namespace OpenSim.Region.ClientStack.LindenUDP
return client; return client;
} }
private void RemoveClient(IClientAPI client) /// <summary>
/// Deactivates the client if we don't receive any packets within a certain amount of time (default 60 seconds).
/// </summary>
/// <remarks>
/// If a connection is active then we will always receive packets even if nothing else is happening, due to
/// regular client pings.
/// </remarks>
/// <param name='client'></param>
private void DeactivateClientDueToTimeout(IClientAPI client)
{ {
// We must set IsLoggingOut synchronously so that we can stop the packet loop reinvoking this method. // We must set IsActive synchronously so that we can stop the packet loop reinvoking this method, even
client.IsLoggingOut = true; // though it's set later on by LLClientView.Close()
client.IsActive = false;
// Fire this out on a different thread so that we don't hold up outgoing packet processing for m_log.WarnFormat(
// everybody else if this is being called due to an ack timeout. "[LLUDPSERVER]: Ack timeout, disconnecting {0} agent for {1} in {2}",
// This is the same as processing as the async process of a logout request. client.SceneAgent.IsChildAgent ? "child" : "root", client.Name, m_scene.RegionInfo.RegionName);
Util.FireAndForget(o => client.Close());
}
private void LogoutClientDueToTimeout(IClientAPI client) StatsManager.SimExtraStats.AddAbnormalClientThreadTermination();
{
// We must set IsLoggingOut synchronously so that we can stop the packet loop reinvoking this method.
client.IsLoggingOut = true;
// Fire this out on a different thread so that we don't hold up outgoing packet processing for if (!client.SceneAgent.IsChildAgent)
// everybody else if this is being called due to an ack timeout.
// This is the same as processing as the async process of a logout request.
Util.FireAndForget(
o =>
{ if (!client.SceneAgent.IsChildAgent)
client.Kick("Simulator logged you out due to connection timeout"); client.Kick("Simulator logged you out due to connection timeout");
client.Close(); });
client.Close();
} }
private void IncomingPacketHandler() private void IncomingPacketHandler()
@ -1450,8 +1452,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP
protected void LogoutHandler(IClientAPI client) protected void LogoutHandler(IClientAPI client)
{ {
client.SendLogoutPacket(); client.SendLogoutPacket();
if (!client.IsLoggingOut) if (!client.IsLoggingOut)
RemoveClient(client); {
client.IsLoggingOut = true;
client.Close();
}
} }
} }
} }