embassy-rs / nrf-softdevice

Apache License 2.0
256 stars 76 forks source link

Connecting to an incorrect Mac address causes a "hang" due to underlying NRF_ERROR_NOT_FOUND #200

Closed sureshjoshi closed 8 months ago

sureshjoshi commented 8 months ago

While trying to connect to a device as a client based on the advertised mac address, my connection appears to be "hanging".

It appears to be caused by this (discovered by adding logging on let ret = raw::sd_ble_evt_get(evt.as_mut_ptr() as *mut u8, &mut len as _); in nrf-softdevice/src/events.rs:

 match RawError::convert(ret) {
                Ok(()) => crate::ble::on_evt(evt.as_ptr() as *const raw::ble_evt_t),
                Err(RawError::NotFound) => break, <== suppressed error
                Err(RawError::BleNotEnabled) => break,
                Err(RawError::DataSize) => panic!("BLE_EVT_MAX_SIZE is too low, use larger evt-max-size feature"),
                Err(err) => panic!("sd_ble_evt_get err {:?}", err),
            }

I'm getting a RawError::NotFound (for some reason, that I need to debug), but that error isn't propagated back to the connection task.

A workaround would be to start a connection timeout, and cancel it - but it feels like that NotFound is incorrectly suppressed.

The problem can be replicated easily by connecting to a fake Mac address.

sureshjoshi commented 8 months ago

Even easier, just set the ScanConfig timeout on the connection:

    /// Timeout in units of 10ms. If set to 0, scan forever.
    pub timeout: u16,

Closing this issue, as I think it might be better to have a non-zero timeout for the ScanConfig, which would capture more cases then just returning the Error above.