Fix service closing pipe after sending command

This commit is contained in:
Jordan Dominion
2023-06-25 21:00:33 -04:00
parent 141a944bf0
commit 7940d301d3
2 changed files with 14 additions and 2 deletions
@@ -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)
@@ -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);