Add IPC backoff/retries and safer disposal

Introduce exponential backoff, jitter and retry logic across IPC components to improve robustness and avoid tight retry loops; make disposal idempotent and add connection guards. Key changes:
- LauncherCoordinatorIpcServer / LauncherIpcServer: add backoff constants, ComputeBackoff(), consecutive error tracking and delayed retries with jitter.
- LanMountainDesktopIpcClient / LauncherIpcClient: add connect retry loops, timeouts, delayed retries, improved error logging, and use ArrayPool for buffered async writes; ensure proper cleanup on failures.
- PublicIpcHostService: add disposed flag, guard OnPeerConnected and Dispose, and clear connected peers on dispose.
- Add many auto-generated commit analysis docs under docs/auto_commit_md and new scripts for analyzing/generating commit docs.
These changes aim to make IPC connection handling more resilient and resource-safe.
This commit is contained in:
lincube
2026-05-07 21:39:21 +08:00
parent 84caca02bf
commit d8f75e86be
159 changed files with 8809 additions and 31 deletions

View File

@@ -6,7 +6,11 @@ namespace LanMountainDesktop.Shared.IPC;
public sealed class LanMountainDesktopIpcClient : IDisposable
{
private const int ConnectRetryCount = 3;
private const int ConnectRetryBaseDelayMs = 500;
private bool _started;
private bool _disposed;
public LanMountainDesktopIpcClient(string? clientPipeName = null)
{
@@ -27,6 +31,21 @@ public sealed class LanMountainDesktopIpcClient : IDisposable
public async Task ConnectAsync(string pipeName = IpcConstants.DefaultPipeName)
{
EnsureStarted();
for (var attempt = 1; attempt <= ConnectRetryCount; attempt++)
{
try
{
Peer = await Provider.GetAndConnectToPeerAsync(pipeName).ConfigureAwait(false);
return;
}
catch (Exception ex) when (attempt < ConnectRetryCount)
{
var delay = ConnectRetryBaseDelayMs * attempt + Random.Shared.Next(0, 200);
await Task.Delay(delay).ConfigureAwait(false);
}
}
Peer = await Provider.GetAndConnectToPeerAsync(pipeName).ConfigureAwait(false);
}
@@ -91,6 +110,13 @@ public sealed class LanMountainDesktopIpcClient : IDisposable
public void Dispose()
{
if (_disposed)
{
return;
}
_disposed = true;
Peer = null;
Provider.Dispose();
}
}