Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit62ee76c

Browse files
committed
fix: fix mutagen controller to release process on exception
1 parent41cf916 commit62ee76c

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

‎App/Services/MutagenController.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616
usingCoder.Desktop.Vpn.Utilities;
1717
usingGrpc.Core;
1818
usingMicrosoft.Extensions.Options;
19+
usingMicrosoft.Extensions.Logging;
20+
usingSerilog;
1921
usingDaemonTerminateRequest=Coder.Desktop.MutagenSdk.Proto.Service.Daemon.TerminateRequest;
2022
usingMutagenProtocol=Coder.Desktop.MutagenSdk.Proto.Url.Protocol;
2123
usingSynchronizationTerminateRequest=Coder.Desktop.MutagenSdk.Proto.Service.Synchronization.TerminateRequest;
24+
usingMicrosoft.Extensions.Hosting;
2225

2326
namespaceCoder.Desktop.App.Services;
2427

@@ -110,6 +113,8 @@ public sealed class MutagenController : ISyncSessionController
110113
// Protects all private non-readonly class members.
111114
privatereadonlyRaiiSemaphoreSlim_lock=new(1,1);
112115

116+
privatereadonlyILogger<MutagenController>_logger;
117+
113118
privatereadonlyCancellationTokenSource_stateUpdateCts=new();
114119
privateTask?_stateUpdateTask;
115120

@@ -139,15 +144,19 @@ public sealed class MutagenController : ISyncSessionController
139144

140145
privatestringMutagenDaemonLog=>Path.Combine(_mutagenDataDirectory,"daemon.log");
141146

142-
publicMutagenController(IOptions<MutagenControllerConfig>config)
147+
publicMutagenController(IOptions<MutagenControllerConfig>config,ILogger<MutagenController>logger)
143148
{
144149
_mutagenExecutablePath=config.Value.MutagenExecutablePath;
150+
_logger=logger;
145151
}
146152

147153
publicMutagenController(stringexecutablePath,stringdataDirectory)
148154
{
149155
_mutagenExecutablePath=executablePath;
150156
_mutagenDataDirectory=dataDirectory;
157+
varbuilder=Host.CreateApplicationBuilder();
158+
builder.Services.AddSerilog();
159+
_logger=(ILogger<MutagenController>)builder.Build().Services.GetService(typeof(ILogger<MutagenController>))!;
151160
}
152161

153162
publiceventEventHandler<SyncSessionControllerStateModel>?StateChanged;
@@ -437,9 +446,9 @@ private async Task<MutagenClient> EnsureDaemon(CancellationToken ct)
437446
{
438447
awaitStopDaemon(cts.Token);
439448
}
440-
catch
449+
catch(ExceptionstopEx)
441450
{
442-
// ignored
451+
_logger.LogError(stopEx,"failed to stop daemon");
443452
}
444453

445454
ReplaceState(newSyncSessionControllerStateModel
@@ -491,6 +500,8 @@ private async Task<MutagenClient> StartDaemon(CancellationToken ct)
491500
}
492501
catch(Exceptione)when(eis notOperationCanceledException)
493502
{
503+
_logger.LogWarning(e,"failed to start daemon process, attempt {attempt} of {maxAttempts}",attempts,
504+
maxAttempts);
494505
if(attempts==maxAttempts)
495506
throw;
496507
// back off a little and try again.
@@ -545,8 +556,11 @@ private void StartDaemonProcess()
545556
// https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.environment?view=net-8.0
546557
_daemonProcess.StartInfo.UseShellExecute=false;
547558
_daemonProcess.StartInfo.RedirectStandardError=true;
548-
// TODO: log exited process
549-
// _daemonProcess.Exited += ...
559+
_daemonProcess.EnableRaisingEvents=true;
560+
_daemonProcess.Exited+=(object?sender,EventArgse)=>
561+
{
562+
_logger.LogInformation("mutagen daemon exited with code {exitCode}",_daemonProcess?.ExitCode);
563+
};
550564
if(!_daemonProcess.Start())
551565
thrownewInvalidOperationException("Failed to start mutagen daemon process, Start returned false");
552566

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp