Skip to content

Commit 3314687

Browse files
committed
fix: Add process exit listener to moduleprocess to further avoid lingering processes
1 parent 52f11bd commit 3314687

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

VRCFaceTracking.ModuleProcess/ModuleProcessMain.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class ModuleProcessMain
2020
public static ILoggerFactory? LoggerFactory;
2121
public static ILogger<ModuleProcessMain> Logger;
2222
public static VrcftSandboxClient Client;
23+
public static CancellationTokenSource cts = new();
2324

2425
private static Queue<IpcPacket> _packetsToSend = new ();
2526

@@ -35,6 +36,15 @@ public static void QueueReceiveEvent()
3536

3637
public static int Main(string[] args)
3738
{
39+
AppDomain.CurrentDomain.ProcessExit += (sender, e) =>
40+
{
41+
Logger.LogInformation("Received SIGTERM");
42+
WaitForPackets = false;
43+
DefModuleAssembly._updateCts.Cancel();
44+
cts.Cancel();
45+
cts.Token.WaitHandle.WaitOne(TimeSpan.FromSeconds(5));
46+
};
47+
3848
try
3949
{
4050
if ( args.Length < 1 )
@@ -260,7 +270,7 @@ static int VrcftMain(string modulePath, int serverPortNumber)
260270
stopwatch.Start();
261271

262272
// Loop infinitely while we wait for commands
263-
while ( WaitForPackets )
273+
while ( WaitForPackets && !cts.IsCancellationRequested)
264274
{
265275
if ( stopwatch.Elapsed.TotalSeconds > CONNECTION_TIMEOUT )
266276
{

0 commit comments

Comments
 (0)