diff --git a/Sources/DatadogSDKTesting/Coverage/DDCoverageHelper.swift b/Sources/DatadogSDKTesting/Coverage/DDCoverageHelper.swift index 5d395ad..3617f24 100644 --- a/Sources/DatadogSDKTesting/Coverage/DDCoverageHelper.swift +++ b/Sources/DatadogSDKTesting/Coverage/DDCoverageHelper.swift @@ -37,6 +37,7 @@ class DDCoverageHelper { coverageWorkQueue = OperationQueue() coverageWorkQueue.qualityOfService = .utility coverageWorkQueue.maxConcurrentOperationCount = max(ProcessInfo.processInfo.activeProcessorCount - 1, 1) + setFileLimit() } func clearCounters() { @@ -47,6 +48,23 @@ class DDCoverageHelper { $0.endCountersFuncPtr) } } + + private func setFileLimit() { + var limit = rlimit() + let filesMax = 4096 + guard getrlimit(RLIMIT_NOFILE, &limit) == 0 else { + Log.debug("Can't get open file limit") + return + } + guard limit.rlim_cur < filesMax else { return } + limit.rlim_cur = rlim_t(filesMax) + limit.rlim_max = rlim_t(filesMax * 8) + if setrlimit(RLIMIT_NOFILE, &limit) == 0 { + Log.debug("Updated open file limit to \(filesMax)") + } else { + Log.debug("Can't increase open file limit") + } + } func setTest(name: String, testSessionId: UInt64, testSuiteId: UInt64, spanId: UInt64) { if !self.initialCoverageSaved { diff --git a/Sources/EventsExporter/CoverageExporter/CoverageExporter.swift b/Sources/EventsExporter/CoverageExporter/CoverageExporter.swift index 81febc8..5c13b26 100644 --- a/Sources/EventsExporter/CoverageExporter/CoverageExporter.swift +++ b/Sources/EventsExporter/CoverageExporter/CoverageExporter.swift @@ -63,7 +63,7 @@ internal class CoverageExporter { do { profData = try DDCoverageConversor.generateProfData(profrawFile: coverage) } catch { - Log.print("Profiler Data genetation failed: \(error)") + Log.print("Profiler Data generation failed: \(error)") return } diff --git a/Sources/EventsExporter/Utils/Spawn.swift b/Sources/EventsExporter/Utils/Spawn.swift index c01925d..ff7be72 100644 --- a/Sources/EventsExporter/Utils/Spawn.swift +++ b/Sources/EventsExporter/Utils/Spawn.swift @@ -51,7 +51,6 @@ public enum Spawn { var childActions: posix_spawn_file_actions_t? dd_posix_spawn_file_actions_init(&childActions) - defer { dd_posix_spawn_file_actions_destroy(&childActions) } let outFile: URL? let errFile: URL? @@ -85,6 +84,8 @@ public enum Spawn { dd_posix_spawn(&pid, command, &childActions, nil, argv, nil) } + dd_posix_spawn_file_actions_destroy(&childActions) + do { try _wait(spawn: ret, pid: pid) } catch let e as RunErrorCode {