From bba1180b11a77a4c1ef5acb5d979cea6ddc2127b Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Thu, 28 May 2026 01:29:30 +0800 Subject: [PATCH] fix holeControlPlane --- Tun/Context/SDLContextActor.swift | 88 ++++++++++++++++--------------- 1 file changed, 46 insertions(+), 42 deletions(-) diff --git a/Tun/Context/SDLContextActor.swift b/Tun/Context/SDLContextActor.swift index 4e01ca7..40cf3b4 100644 --- a/Tun/Context/SDLContextActor.swift +++ b/Tun/Context/SDLContextActor.swift @@ -297,48 +297,6 @@ actor SDLContextActor { } } - private static func runRestarting( - name: String, - retryDelay: Duration = .seconds(5), - operation: @escaping @Sendable () async throws -> Void - ) async throws { - while !Task.isCancelled { - do { - try Task.checkCancellation() - try await operation() - SDLLogger.log("[SDLContext] worker \(name) ended, will restart", for: .debug) - } catch is CancellationError { - SDLLogger.log("[SDLContext] worker \(name) cancelled", for: .debug) - throw CancellationError() - } catch { - SDLLogger.log("[SDLContext] worker \(name) crashed: \(error.localizedDescription), will restart", for: .debug) - } - - try await Task.sleep(for: retryDelay) - } - } - - private static func runPeriodic( - name: String, - interval: Duration, - retryDelay: Duration = .seconds(5), - operation: @escaping @Sendable () async throws -> Void - ) async throws { - while !Task.isCancelled { - do { - try Task.checkCancellation() - try await operation() - try await Task.sleep(for: interval) - } catch is CancellationError { - SDLLogger.log("[SDLContext] worker \(name) cancelled", for: .debug) - throw CancellationError() - } catch { - SDLLogger.log("[SDLContext] worker \(name) crashed: \(error.localizedDescription), will retry", for: .debug) - try await Task.sleep(for: retryDelay) - } - } - } - private func runIPv6AssistSupervisor() async throws { do { for await assistInfo in self.ipv6AssistEvents { @@ -583,3 +541,49 @@ extension SDLContextActor { } } + +extension SDLContextActor { + + private static func runRestarting( + name: String, + retryDelay: Duration = .seconds(5), + operation: @escaping @Sendable () async throws -> Void + ) async throws { + while !Task.isCancelled { + do { + try Task.checkCancellation() + try await operation() + SDLLogger.log("[SDLContext] worker \(name) ended, will restart", for: .debug) + } catch is CancellationError { + SDLLogger.log("[SDLContext] worker \(name) cancelled", for: .debug) + throw CancellationError() + } catch { + SDLLogger.log("[SDLContext] worker \(name) crashed: \(error.localizedDescription), will restart", for: .debug) + } + + try await Task.sleep(for: retryDelay) + } + } + + private static func runPeriodic( + name: String, + interval: Duration, + retryDelay: Duration = .seconds(5), + operation: @escaping @Sendable () async throws -> Void + ) async throws { + while !Task.isCancelled { + do { + try Task.checkCancellation() + try await operation() + try await Task.sleep(for: interval) + } catch is CancellationError { + SDLLogger.log("[SDLContext] worker \(name) cancelled", for: .debug) + throw CancellationError() + } catch { + SDLLogger.log("[SDLContext] worker \(name) crashed: \(error.localizedDescription), will retry", for: .debug) + try await Task.sleep(for: retryDelay) + } + } + } + +}