Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fping crashes with __darwin_check_fd_set_overflow. Please help to resolve the issue. #316

Open
Karthikeyan1108 opened this issue May 1, 2024 · 3 comments

Comments

@Karthikeyan1108
Copy link

Thank you for the amazing framework.

There is a crash observed in the fping framework. Please help us to resolve the crash.

Crashed Thread: 7

Exception Type: EXC_GUARD
Exception Codes: GUARD_TYPE_USER
Exception Codes: 0x6000000000000012, 0x0000000000000002

Termination Reason: Namespace LIBSYSTEM, Code 2 Application Triggered Fault

Thread 7 Crashed:
0 libsystem_kernel.dylib 0x199e8ced8 os_fault_with_payload + 8
1 libsystem_kernel.dylib 0x199e94784 __darwin_check_fd_set_overflow + 212
2 pingo 0x1058ec944 socket_can_read + 192
3 pingo 0x1058eb510 wait_for_reply + 124
4 pingo 0x1058eb084 main_loop + 692
5 pingo 0x1058ea0dc mainx + 3384
6 pingo 0x1058e9324 fping + 48
7 Versa SASE Client 0x105012768 0x104e78000 + 1681256
8 Versa SASE Client 0x104ef57ac 0x104e78000 + 513964
9 libdispatch.dylib 0x199d0c750 _dispatch_call_block_and_release + 32
10 libdispatch.dylib 0x199d0e3e8 _dispatch_client_callout + 20
11 libdispatch.dylib 0x199d20080 _dispatch_root_queue_drain + 864
12 libdispatch.dylib 0x199d206b8 _dispatch_worker_thread2 + 156
13 libsystem_pthread.dylib 0x199ebafd0 _pthread_wqthread + 228
14 libsystem_pthread.dylib 0x199eb9d28 start_wqthread + 8

@auerswal
Copy link
Collaborator

auerswal commented May 4, 2024

Please provide additional details about your use of fping.

@Karthikeyan1108
Copy link
Author

Hi @auerswal

Thank you for the reply. Please find the usage of fping in the following code. Passing array of hosts to the ping operation in the background queue async way with arguments as below.

`/// Send ping with completion block.
///
/// - Parameters:
/// - hosts: hosts
/// - backoff: default 1.5
/// - count: number of ping send per host
/// - completion: results dictionary, the key is host string, the value is PngResult struct

public static func ping(hosts: [String], backoff: Float = 1.5, count: Int = 1,
                        progress: ((_ progress: (Float)) -> Void)? = nil,
                        completion: @escaping (_ results: [String: PngResult]) -> Void) {

    let argv:[String?] = ["", "-c\(count)", "-B\(backoff)", "-q"] + hosts + [nil]
    var cargs = argv.map { $0.flatMap { UnsafeMutablePointer<Int8>(strdup($0)) } }

    let observer = NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "fpingxProgress"), object: nil, queue: OperationQueue()) { (notification) in
        if let p = notification.userInfo!["progress"] as? Float {
            progress?(p > 1 ? 1 : p)
        }
    }

    DispatchQueue.global(qos: .background).async {
        let resultsArrarPtr = fping(Int32(argv.count), &cargs, progressCCallback)!
        var hostPtr = resultsArrarPtr.pointee

        var results: [String: PngResult] = [:]
        while (hostPtr != nil) {
            let h = hostPtr!.pointee
            let host = String(cString: h.host)
            let result = PngResult(host: host, xmt: Int(h.num_sent), rcv: Int(h.num_recv), avg: h.num_recv > 0 ? Float(h.total_time / h.num_recv / 100) : nil, min: h.num_recv > 0 ? Int(h.min_reply / 100) : nil, max: h.num_recv > 0 ? Int(h.max_reply / 100) : nil, jitt: (h.jitter / Float(count)))
            results[host] = result
            let freeNode = hostPtr
            hostPtr = hostPtr?.pointee.ev_next
            free(UnsafeMutableRawPointer(freeNode))
        }

        free(UnsafeMutablePointer(resultsArrarPtr))
        completion(results)
        NotificationCenter.default.removeObserver(observer)
        for ptr in cargs { free(UnsafeMutablePointer(ptr)) }
    }

}`

@auerswal
Copy link
Collaborator

The error looks as if you created a too restrictive environment for fping to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants