public async Task <(long length, Guid packId, MessageType messageType, Stream data)> ReadMessage() { await readindMessageSemaphore.WaitAsync(); try { long length = reader.ReadInt64(); Guid packId = new Guid(reader.ReadBytes(16)); MessageType type = (MessageType)reader.ReadByte(); logger.LogDebug($"READ ID : {packId} Type : {type}"); if (type == MessageType.PingResponse) { Pinger.SetPing(packId); return(await ReadMessage()); } return(length, packId, type, tcpClient.GetStream().Partial(length)); } catch (Exception ex) { logger.LogWarning(ex, "Error while reading"); ConnectionLost(); throw; } finally { readindMessageSemaphore.Release(); } }