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

Commit5b08cca

Browse files
committed
fix: fix mutagen controller to release process on exception
1 parentb803aa1 commit5b08cca

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;
@@ -440,9 +449,9 @@ private async Task<MutagenClient> EnsureDaemon(CancellationToken ct)
440449
{
441450
awaitStopDaemon(cts.Token);
442451
}
443-
catch
452+
catch(ExceptionstopEx)
444453
{
445-
// ignored
454+
_logger.LogError(stopEx,"failed to stop daemon");
446455
}
447456

448457
ReplaceState(newSyncSessionControllerStateModel
@@ -494,6 +503,8 @@ private async Task<MutagenClient> StartDaemon(CancellationToken ct)
494503
}
495504
catch(Exceptione)when(eis notOperationCanceledException)
496505
{
506+
_logger.LogWarning(e,"failed to start daemon process, attempt {attempt} of {maxAttempts}",attempts,
507+
maxAttempts);
497508
if(attempts==maxAttempts)
498509
throw;
499510
// back off a little and try again.
@@ -548,8 +559,11 @@ private void StartDaemonProcess()
548559
// https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.environment?view=net-8.0
549560
_daemonProcess.StartInfo.UseShellExecute=false;
550561
_daemonProcess.StartInfo.RedirectStandardError=true;
551-
// TODO: log exited process
552-
// _daemonProcess.Exited += ...
562+
_daemonProcess.EnableRaisingEvents=true;
563+
_daemonProcess.Exited+=(object?sender,EventArgse)=>
564+
{
565+
_logger.LogInformation("mutagen daemon exited with code {exitCode}",_daemonProcess?.ExitCode);
566+
};
553567
if(!_daemonProcess.Start())
554568
thrownewInvalidOperationException("Failed to start mutagen daemon process, Start returned false");
555569

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp