fix : 코드 분석 후 버그 및 결함 16건 수정

- ARepository 전체 메서드 IDbConnection using 추가 (커넥션 풀 누수)
- GameServer NotImplementedException → 로그 출력으로 변경
- ServerBase Auth/Echo payload 길이 검증 주석 해제
- PacketSerializer MemoryStream using 추가 (양쪽 솔루션)
- PacketSerializer size 파라미터 제거, 자동 계산 + size 검증 구현
- ServerBase NetDataWriter cachedWriter 재사용 (GC 압력 감소)
- ServerBase isListening volatile 추가
- ServerBase Deserialize 실패 시 null payload 체크
- ServerBase Serilog 구조적 로깅 템플릿 구문 수정
- TestHandler 전체 메서드 try-catch 추가
- TestRepository IDbConnectionFactory 인터페이스로 변경
- DummyClients BodyLength 계산 불일치 수정
- DummyClients pendingPings 메모리 누수 방지
- EchoClientTester async void 이벤트 → 동기 Cancel()로 변경
- ANALYSIS.md 코드 분석 및 문제점 보고서 추가

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-03 01:09:27 +09:00
parent d73487df5b
commit cf2be6b125
10 changed files with 339 additions and 91 deletions

View File

@@ -7,22 +7,21 @@ namespace ClientTester.Packet
public static class PacketSerializer
{
// 직렬화: 객체 → byte[]
public static byte[] Serialize<T>(ushort type, ushort size, T packet)
// 직렬화: 객체 → byte[] (size는 payload 크기로 자동 계산)
public static byte[] Serialize<T>(ushort type, T packet)
{
MemoryStream ms = new MemoryStream();
using MemoryStream payloadMs = new MemoryStream();
Serializer.Serialize(payloadMs, packet);
byte[] payload = payloadMs.ToArray();
ushort size = (ushort)payload.Length;
// 2바이트 패킷 타입 헤더
ms.WriteByte((byte)(type & 0xFF));
ms.WriteByte((byte)(type >> 8));
// 2바이트 패킷 길이 헤더
ms.WriteByte((byte)(size & 0xFF));
ms.WriteByte((byte)(size >> 8));
// protobuf 페이로드
Serializer.Serialize(ms, packet);
return ms.ToArray();
byte[] result = new byte[4 + payload.Length];
result[0] = (byte)(type & 0xFF);
result[1] = (byte)(type >> 8);
result[2] = (byte)(size & 0xFF);
result[3] = (byte)(size >> 8);
Buffer.BlockCopy(payload, 0, result, 4, payload.Length);
return result;
}
// 역직렬화: byte[] → (PacketType, payload bytes)
@@ -34,19 +33,25 @@ namespace ClientTester.Packet
return (0, 0, null)!;
}
// 길이체크도 필요함
ushort type = (ushort)(data[0] | (data[1] << 8));
ushort size = (ushort)(data[2] | (data[3] << 8));
byte[] payload = new byte[data.Length - 4];
Buffer.BlockCopy(data, 4, payload, 0, payload.Length);
int actualPayloadLen = data.Length - 4;
if (size > actualPayloadLen)
{
Log.Warning("[PacketSerializer] 페이로드 크기 불일치 HeaderSize={Size} ActualSize={Actual}", size, actualPayloadLen);
return (0, 0, null)!;
}
byte[] payload = new byte[size];
Buffer.BlockCopy(data, 4, payload, 0, size);
return (type, size, payload);
}
// 페이로드 → 특정 타입으로 역직렬화
public static T DeserializePayload<T>(byte[] payload)
{
MemoryStream ms = new MemoryStream(payload);
using MemoryStream ms = new MemoryStream(payload);
return Serializer.Deserialize<T>(ms);
}
}