From afa4ad9e91ae1da6d52f4c178921747159316ea2 Mon Sep 17 00:00:00 2001 From: k1mlka Date: Mon, 2 Dec 2024 18:48:40 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E7=B4=A7=E6=80=A5=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E8=AF=81=E4=B9=A6=E6=9C=89=E6=95=88=E6=9C=9F=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=20Timer=20=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../YarpReverseProxyServiceImpl.cs | 47 ++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services.Implementation/YarpReverseProxyServiceImpl.cs b/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services.Implementation/YarpReverseProxyServiceImpl.cs index 4621bfc369d..c3e20122be1 100644 --- a/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services.Implementation/YarpReverseProxyServiceImpl.cs +++ b/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services.Implementation/YarpReverseProxyServiceImpl.cs @@ -48,26 +48,41 @@ protected override void CheckRootCertificate() platformService, CertificateManager); - X509Certificate2? cer = CertificateManager.RootCertificatePackable; - if (cer is not null && DateTime.Now <= cer.NotAfter && cer.NotAfter <= DateTime.Now.AddMonths(1)) + try { - var interval = cer.NotAfter - DateTime.Now; - - _certificateTimer = new System.Timers.Timer(interval) + X509Certificate2? cer = CertificateManager.RootCertificatePackable; + if (cer is not null && + DateTime.Now <= cer.NotAfter && cer.NotAfter <= DateTime.Now.AddMilliseconds(int.MaxValue)) { - AutoReset = false, - }; + var interval = cer.NotAfter - DateTime.Now; - _certificateTimer.Elapsed += async (_, _) => - { - ICertificateManager.Constants.CheckRootCertificate( - platformService, - CertificateManager); + _certificateTimer = new System.Timers.Timer(interval) + { + AutoReset = false, + }; - await StopProxyAsync(); - await StartProxyImpl(); - }; - _certificateTimer.Start(); + _certificateTimer.Elapsed += async (_, _) => + { + try + { + ICertificateManager.Constants.CheckRootCertificate( + platformService, + CertificateManager); + + await StopProxyAsync(); + await StartProxyImpl(); + } + catch (Exception e) + { + e.LogAndShowT(TAG, msg: "CheckRootCertificate in Timer.Elapsed Error"); + } + }; + _certificateTimer.Start(); + } + } + catch (Exception e) + { + e.LogAndShowT(TAG, msg: "CheckRootCertificate Error"); } } }