提交 56516202 编写于 作者: T tanghai

1.修复Log文件命名日期格式不一致的问题

2.ActorLocationSender在收到所有发送消息的确认后及时回收
3.LastSendTime应该改成LastRecvTime,因为如果对方挂掉了,发送方假如一直发送,这个ActorLocationSender也会一直无法回收,正确的逻辑应该是1分钟没有收到确认就应该认为发送失败,回收ActorLocationSender
上级 e9a60dee
......@@ -21,7 +21,7 @@
<targets>
<target name="debug" xsi:type="File"
openFileCacheTimeout="3600"
fileName="${basedir}/../Logs/Log-${var:appType}-${var:appIdFormat}-Debug-${shortdate}.log"
fileName="${basedir}/../Logs/Log-${var:appType}-${var:appIdFormat}-Debug-${date:universalTime=true:format=yyyyMMdd}.log"
deleteOldFileOnStartup="false"
layout="${longdate} ${var:appTypeFormat} ${var:appIdFormat} ${callsite:className=false:methodName=false:fileName=true:includeSourcePath=false:skipFrames=2} ${message}" />
</targets>
......
......@@ -12,6 +12,7 @@ namespace ETHotfix
}
// 每10s扫描一次过期的actorproxy进行回收,过期时间是1分钟
// 可能由于bug或者进程挂掉,导致ActorLocationSender发送的消息没有确认,结果无法自动删除,每一分钟清理一次这种ActorLocationSender
public async ETVoid StartAsync(ActorLocationSenderComponent self)
{
List<long> timeoutActorProxyIds = new List<long>();
......@@ -36,7 +37,7 @@ namespace ETHotfix
continue;
}
if (timeNow < actorLocationMessageSender.LastSendTime + 60 * 1000)
if (timeNow < actorLocationMessageSender.LastRecvTime + 60 * 1000)
{
continue;
}
......
......@@ -8,10 +8,11 @@ namespace ETHotfix
{
public override void Awake(ActorLocationSender self)
{
self.LastSendTime = TimeHelper.Now();
self.LastRecvTime = TimeHelper.Now();
self.Tcs = null;
self.FailTimes = 0;
self.ActorId = 0;
self.WaitingTasks.Clear();
}
}
......@@ -26,9 +27,6 @@ namespace ETHotfix
public async ETVoid StartAsync(ActorLocationSender self)
{
self.ActorId = await Game.Scene.GetComponent<LocationProxyComponent>().Get(self.Id);
self.Address = StartConfigComponent.Instance.GetInnerAddress(IdGenerater.GetAppId(self.ActorId));
self.UpdateAsync().Coroutine();
}
}
......@@ -41,10 +39,10 @@ namespace ETHotfix
self.RunError(ErrorCode.ERR_ActorRemove);
self.Id = 0;
self.LastSendTime = 0;
self.Address = null;
self.LastRecvTime = 0;
self.ActorId = 0;
self.FailTimes = 0;
self.WaitingTasks.Clear();
self.Tcs = null;
}
}
......@@ -109,22 +107,24 @@ namespace ETHotfix
long instanceId = self.InstanceId;
while (true)
{
if (self.InstanceId != instanceId)
{
return;
}
ActorTask actorTask = await self.GetAsync();
if (self.InstanceId != instanceId)
{
return;
}
if (actorTask.ActorRequest == null)
{
return;
}
await self.RunTask(actorTask);
if (self.InstanceId != instanceId)
{
return;
}
}
}
catch (Exception e)
......@@ -158,7 +158,6 @@ namespace ETHotfix
// 等待0.5s再发送
await Game.Scene.GetComponent<TimerComponent>().WaitAsync(500);
self.ActorId = await Game.Scene.GetComponent<LocationProxyComponent>().Get(self.Id);
self.Address = StartConfigComponent.Instance.GetInnerAddress(IdGenerater.GetAppId(self.ActorId));
self.AllowGet();
return;
......@@ -168,21 +167,25 @@ namespace ETHotfix
return;
default:
self.LastSendTime = TimeHelper.Now();
self.LastRecvTime = TimeHelper.Now();
self.FailTimes = 0;
self.WaitingTasks.Dequeue();
if (task.Tcs == null)
// 如果所有的发送消息都得到了返回,发送任务完成,那么删除这个ActorLocationSender,及时回收发送对象
if (self.WaitingTasks.Count == 0)
{
return;
self.GetParent<ActorLocationSenderComponent>().Remove(self.Id);
}
IActorLocationResponse actorLocationResponse = response as IActorLocationResponse;
if (actorLocationResponse == null)
if (task.Tcs != null)
{
task.Tcs.SetException(new Exception($"actor location respose is not IActorLocationResponse, but is: {response.GetType().Name}"));
IActorLocationResponse actorLocationResponse = response as IActorLocationResponse;
if (actorLocationResponse == null)
{
task.Tcs.SetException(new Exception($"actor location respose is not IActorLocationResponse, but is: {response.GetType().Name}"));
}
task.Tcs.SetResult(actorLocationResponse);
}
task.Tcs.SetResult(actorLocationResponse);
return;
}
}
......
......@@ -6,16 +6,13 @@ namespace ETModel
// 知道对方的Id,使用这个类发actor消息
public class ActorLocationSender : ComponentWithId
{
// actor的地址
public IPEndPoint Address;
public long ActorId;
// 还没发送的消息
public Queue<ActorTask> WaitingTasks = new Queue<ActorTask>();
// 最近发送消息的时间
public long LastSendTime;
// 最近接收消息的时间
public long LastRecvTime;
public int FailTimes;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册