Skip to content

Commit

Permalink
Fix issue with ESMessage cancellation on global queue
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkenso committed Nov 14, 2024
1 parent 196d1c6 commit 247b38f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 247b38f

Please sign in to comment.