From 776f7eb7d33bada628371d6b92d253d172aaad9d Mon Sep 17 00:00:00 2001 From: lindexi Date: Mon, 30 Oct 2023 14:09:54 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=8A=A0=E4=B8=8A=E6=9B=B4=E5=A4=9A?= =?UTF-8?q?=E8=B0=83=E8=AF=95=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dotnetCampus.Ipc/Internals/PeerManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dotnetCampus.Ipc/Internals/PeerManager.cs b/src/dotnetCampus.Ipc/Internals/PeerManager.cs index fac3ff8..19cc16c 100644 --- a/src/dotnetCampus.Ipc/Internals/PeerManager.cs +++ b/src/dotnetCampus.Ipc/Internals/PeerManager.cs @@ -35,7 +35,7 @@ public void RemovePeerProxy(PeerProxy peerProxy) { if (!peerProxy.IsBroken) { - throw new ArgumentException($"Must remove the Broken peer"); + throw new ArgumentException($"Must remove the Broken peer. PeerName={peerProxy.PeerName}"); } ConnectedServerManagerList.TryRemove(peerProxy.PeerName, out var value); From 72a310c72afd04a16ae378e3ee5fff8551ebba54 Mon Sep 17 00:00:00 2001 From: lindexi Date: Mon, 30 Oct 2023 14:13:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E9=A1=B6=E5=B1=82=E6=8A=9B=E5=87=BA=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Internals/PeerReConnector.cs | 26 ++++++++++++------- src/dotnetCampus.Ipc/Pipes/PeerProxy.cs | 19 ++++++++++---- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/dotnetCampus.Ipc/Internals/PeerReConnector.cs b/src/dotnetCampus.Ipc/Internals/PeerReConnector.cs index 96b3def..4f58c44 100644 --- a/src/dotnetCampus.Ipc/Internals/PeerReConnector.cs +++ b/src/dotnetCampus.Ipc/Internals/PeerReConnector.cs @@ -34,18 +34,26 @@ private void PeerProxy_PeerConnectionBroken(object? sender, IPeerConnectionBroke private async void Reconnect() { - var ipcClientService = _ipcProvider.CreateIpcClientService(_peerProxy.PeerName); - var success = await TryReconnectAsync(ipcClientService); - - if (success) + try { - _peerProxy.Reconnect(ipcClientService); + var ipcClientService = _ipcProvider.CreateIpcClientService(_peerProxy.PeerName); + var success = await TryReconnectAsync(ipcClientService); + + if (success) + { + _peerProxy.Reconnect(ipcClientService); + } + else + { + _ipcProvider.IpcContext.Logger.Error($"[PeerReConnector][Reconnect] Fail. PeerName={_peerProxy.PeerName}"); + + ReconnectFail?.Invoke(this, new ReconnectFailEventArgs(_peerProxy, _ipcProvider)); + } } - else + catch (Exception e) { - _ipcProvider.IpcContext.Logger.Error($"[PeerReConnector][Reconnect] Fail. PeerName={_peerProxy.PeerName}"); - - ReconnectFail?.Invoke(this, new ReconnectFailEventArgs(_peerProxy, _ipcProvider)); + // 线程顶层,吃掉所有的异常 + _ipcProvider.IpcContext.Logger.Error(e, $"[PeerReConnector][Reconnect] Reconnect Peer Fail. PeerName={_peerProxy.PeerName}"); } } diff --git a/src/dotnetCampus.Ipc/Pipes/PeerProxy.cs b/src/dotnetCampus.Ipc/Pipes/PeerProxy.cs index 39e440f..41383ec 100644 --- a/src/dotnetCampus.Ipc/Pipes/PeerProxy.cs +++ b/src/dotnetCampus.Ipc/Pipes/PeerProxy.cs @@ -7,6 +7,7 @@ using dotnetCampus.Ipc.Exceptions; using dotnetCampus.Ipc.Internals; using dotnetCampus.Ipc.Messages; +using dotnetCampus.Ipc.Utils.Extensions; using Newtonsoft.Json.Schema; namespace dotnetCampus.Ipc.Pipes @@ -212,14 +213,22 @@ internal void Update(IpcInternalPeerConnectedArgs ipcInternalPeerConnectedArgs) /// internal async void Reconnect(IpcClientService ipcClientService) { - Debug.Assert(ipcClientService.PeerName == PeerName); + try + { + Debug.Assert(ipcClientService.PeerName == PeerName); - IpcClientService = ipcClientService; + IpcClientService = ipcClientService; - // 等待完成更新之后,再进行通知,否则将会在收到事件时,还在准备完成所有逻辑 - await WaitForFinishedTaskCompletionSource.Task; + // 等待完成更新之后,再进行通知,否则将会在收到事件时,还在准备完成所有逻辑 + await WaitForFinishedTaskCompletionSource.Task; - PeerReconnected?.Invoke(this, new PeerReconnectedArgs()); + PeerReconnected?.Invoke(this, new PeerReconnectedArgs()); + } + catch (Exception e) + { + // 线程顶层,不能再抛出异常 + IpcContext.Logger.Error(e, $"[PeerProxy] Reconnect Fail. PeerName={PeerName}"); + } } private void ServerStreamMessageReader_PeerConnectBroke(object? sender, PeerConnectionBrokenArgs e)