From 7940d301d3dced007c18f017fd5ccdc163ba1cb4 Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Sun, 25 Jun 2023 20:03:41 -0400 Subject: [PATCH] Fix service closing pipe after sending command --- src/Tgstation.Server.Host.Service/ServerService.cs | 14 +++++++++++++- .../Core/CommandPipeReader.cs | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Tgstation.Server.Host.Service/ServerService.cs b/src/Tgstation.Server.Host.Service/ServerService.cs index b5a7434c68..c615bc592c 100644 --- a/src/Tgstation.Server.Host.Service/ServerService.cs +++ b/src/Tgstation.Server.Host.Service/ServerService.cs @@ -2,7 +2,9 @@ using System.Diagnostics; using System.IO; using System.IO.Pipes; +using System.Linq; using System.ServiceProcess; +using System.Text; using System.Threading; using System.Threading.Tasks; @@ -203,7 +205,17 @@ namespace Tgstation.Server.Host.Service logger.LogDebug("Send command: {command}", command); try { - using var streamWriter = new StreamWriter(localPipeServer); + var encoding = Encoding.UTF8; + using var streamWriter = new StreamWriter( + localPipeServer, + encoding, + PipeCommands + .AllCommands + .Select( + command => encoding.GetByteCount( + command + Environment.NewLine)) + .Max(), + true); streamWriter.WriteLine(command); } catch (Exception ex) diff --git a/src/Tgstation.Server.Host/Core/CommandPipeReader.cs b/src/Tgstation.Server.Host/Core/CommandPipeReader.cs index a1afa80cbe..073f5a1e42 100644 --- a/src/Tgstation.Server.Host/Core/CommandPipeReader.cs +++ b/src/Tgstation.Server.Host/Core/CommandPipeReader.cs @@ -84,7 +84,7 @@ namespace Tgstation.Server.Host.Core await serverControl.GracefulShutdown(true); break; case null: - logger.LogDebug("Read null from pipe"); + logger.LogError("Read null from pipe!"); return; default: logger?.LogWarning("Unrecognized pipe command: {command}", line);