diff --git a/EndpointSecurity/Sources/SpellbookEndpointSecurity/ESClient/ESClient.swift b/EndpointSecurity/Sources/SpellbookEndpointSecurity/ESClient/ESClient.swift index c9de82d..4523e7d 100644 --- a/EndpointSecurity/Sources/SpellbookEndpointSecurity/ESClient/ESClient.swift +++ b/EndpointSecurity/Sources/SpellbookEndpointSecurity/ESClient/ESClient.swift @@ -72,6 +72,7 @@ public final class ESClient: ESClientProtocol { self.client = client self.pathMutes = ESMutePath(client: client) self.processMutes = ESMuteProcess(client: client) + self.timeoutQueue = DispatchQueue(label: "\(Self.self).timeout.queue", autoreleaseFrequency: .workItem) do { self.timebaseInfo = try mach_timebase_info.system() @@ -319,6 +320,7 @@ public final class ESClient: ESClientProtocol { private let pathMutes: ESMutePath private let processMutes: ESMuteProcess private let timebaseInfo: mach_timebase_info? + private let timeoutQueue: DispatchQueue @inline(__always) private func handleMessage(_ message: ESMessagePtr) { @@ -396,7 +398,7 @@ public final class ESClient: ESClientProtocol { } let item = DispatchWorkItem(block: cancellation) - DispatchQueue.global().asyncAfter(deadline: .now() + interval, execute: item) + timeoutQueue.asyncAfter(delay: interval, execute: item) return item } diff --git a/EndpointSecurity/Sources/SpellbookEndpointSecurity/ESClient/ESMuteProcess.swift b/EndpointSecurity/Sources/SpellbookEndpointSecurity/ESClient/ESMuteProcess.swift index 9428823..dcd9466 100644 --- a/EndpointSecurity/Sources/SpellbookEndpointSecurity/ESClient/ESMuteProcess.swift +++ b/EndpointSecurity/Sources/SpellbookEndpointSecurity/ESClient/ESMuteProcess.swift @@ -39,15 +39,10 @@ internal final class ESMuteProcess { self.cleanupDelay = cleanupDelay self.environment = environment - scheduleCleanupDiedProcesses() - } - - private func scheduleCleanupDiedProcesses() { - DispatchQueue.global().asyncAfter(deadline: .now() + cleanupDelay) { [weak self] in - guard let self else { return } - self.cleanupDiedProcesses() - self.scheduleCleanupDiedProcesses() - } + DispatchQueue(label: "ESMuteProcess.cleanup.queue", autoreleaseFrequency: .workItem) + .asyncPeriodically(interval: cleanupDelay, immediately: false) { [weak self] in + self?.cleanupDiedProcesses() != nil + } } private func cleanupDiedProcesses() { diff --git a/Package.swift b/Package.swift index aa18c57..74d3ca2 100644 --- a/Package.swift +++ b/Package.swift @@ -21,7 +21,7 @@ let package = Package( .library(name: "s_libproc", targets: ["s_libproc"]), ], dependencies: [ - .package(url: "https://github.com/Alkenso/SwiftSpellbook.git", from: "1.1.1"), + .package(url: "https://github.com/Alkenso/SwiftSpellbook.git", from: "1.1.3"), ], targets: [ // MacShims.