mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-20 23:54:26 +08:00
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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user