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

fix: fix daemon.lock race on mutagen startup#101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
spikecurtis merged 1 commit intomainfromspike/daemon-startup-race
May 14, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletionsApp/Services/MutagenController.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -441,6 +441,7 @@ private async Task<SyncSessionControllerStateModel> UpdateState(MutagenClient cl
/// </summary>
privateasyncTask<MutagenClient>EnsureDaemon(CancellationTokenct)
{
_logger.LogDebug("EnsureDaemon called");
ObjectDisposedException.ThrowIf(_disposing,typeof(MutagenController));
if(_mutagenClient!=null&&_daemonProcess!=null)
return_mutagenClient;
Expand DownExpand Up@@ -479,12 +480,14 @@ private async Task<MutagenClient> EnsureDaemon(CancellationToken ct)
/// </summary>
privateasyncTask<MutagenClient>StartDaemon(CancellationTokenct)
{
_logger.LogDebug("StartDaemon called");
// Stop the running daemon
if(_daemonProcess!=null)awaitStopDaemon(ct);

// Attempt to stop any orphaned daemon
try
{
_logger.LogDebug("creating MutagenClient to stop orphan");
varclient=newMutagenClient(_mutagenDataDirectory);
awaitclient.Daemon.TerminateAsync(newDaemonTerminateRequest(),cancellationToken:ct);
}
Expand All@@ -496,6 +499,10 @@ private async Task<MutagenClient> StartDaemon(CancellationToken ct)
{
// Mainline; no daemon running.
}
finally
{
_logger.LogDebug("finished with orphan mutagen client");
}

// If we get some failure while creating the log file or starting the process, we'll retry
// it up to 5 times x 100ms. Those issues should resolve themselves quickly if they are
Expand DownExpand Up@@ -528,6 +535,7 @@ private async Task<MutagenClient> StartDaemon(CancellationToken ct)
ct.ThrowIfCancellationRequested();
try
{
_logger.LogDebug("creating mainline mutagen client");
varclient=newMutagenClient(_mutagenDataDirectory);
_=awaitclient.Daemon.VersionAsync(newVersionRequest(),cancellationToken:ct);
_mutagenClient=client;
Expand Down
20 changes: 0 additions & 20 deletionsMutagenSdk/MutagenClient.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,26 +16,6 @@ public class MutagenClient : IDisposable

public MutagenClient(string dataDir)
{
// Check for the lock file first, since it should exist if it's running.
var daemonLockFile = Path.Combine(dataDir, "daemon", "daemon.lock");
if (!File.Exists(daemonLockFile))
throw new FileNotFoundException(
"Mutagen daemon lock file not found, did the mutagen daemon start successfully?", daemonLockFile);

// We should not be able to open the lock file.
try
{
using var _ = File.Open(daemonLockFile, FileMode.Open, FileAccess.Write, FileShare.None);
// We throw a FileNotFoundException if we could open the file because
// it means the same thing and allows us to return the path nicely.
throw new InvalidOperationException(
$"Mutagen daemon lock file '{daemonLockFile}' is unlocked, did the mutagen daemon start successfully?");
}
catch (IOException)
{
// this is what we expect
}

// Read the IPC named pipe address from the sock file.
var daemonSockFile = Path.Combine(dataDir, "daemon", "daemon.sock");
if (!File.Exists(daemonSockFile))
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp