소스 검색

fix(session): fix session timeout detection and tcp listener exception not released

master
yedajiang44 11 달 전
부모
커밋
eb0ddd90a6
2개의 변경된 파일12개의 추가작업 그리고 6개의 파일을 삭제
  1. +2
    -2
      src/JT808.Gateway/JT808TcpServer.cs
  2. +10
    -4
      src/JT808.Gateway/Services/JT808TcpReceiveTimeoutHostedService.cs

+ 2
- 2
src/JT808.Gateway/JT808TcpServer.cs 파일 보기

@@ -114,7 +114,7 @@ namespace JT808.Gateway
var pipe = new Pipe();
Task writing = FillPipeAsync(session, pipe.Writer);
Task reading = ReadPipeAsync(session, pipe.Reader);
await Task.WhenAll(reading, writing);
await Task.WhenAny(reading, writing);
SessionManager.RemoveBySessionId(session.SessionID);
}, jT808TcpSession);
}
@@ -245,7 +245,7 @@ namespace JT808.Gateway
}
catch (JT808Exception ex)
{
Logger.LogError($"[HeaderDeserialize ErrorCode]:{ ex.ErrorCode},[ReaderBuffer]:{data?.ToHexString()},{session.Client.RemoteEndPoint},{session.TerminalPhoneNo}");
Logger.LogError($"[HeaderDeserialize ErrorCode]:{ex.ErrorCode},[ReaderBuffer]:{data?.ToHexString()},{session.Client.RemoteEndPoint},{session.TerminalPhoneNo}");
}
totalConsumed += seqReader.Consumed - totalConsumed;
if (seqReader.End) break;


+ 10
- 4
src/JT808.Gateway/Services/JT808TcpReceiveTimeoutHostedService.cs 파일 보기

@@ -4,8 +4,6 @@ using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

@@ -37,9 +35,17 @@ namespace JT808.Gateway.Services
{
foreach (var item in SessionManager.GetTcpAll())
{
if (item.ActiveTime.AddSeconds(Configuration.TcpReaderIdleTimeSeconds) < DateTime.Now)
try
{
item.ReceiveTimeout.Cancel();
if (item.ActiveTime.AddSeconds(Configuration.TcpReaderIdleTimeSeconds) < DateTime.Now)
{
item.ReceiveTimeout.Cancel();
}
}
catch (Exception e)
{
Logger.LogError(e, "Check whether the session with id {id} and sim number {terminal} has timed out and failed.", item.SessionID, item.TerminalPhoneNo);
continue;
}
}
Logger.LogInformation($"[Check Receive Timeout]");


불러오는 중...
취소
저장