sd_ble_gap_connect times out, but BLE_GAP_EVT_TIMEOUT never fires

Im on an nRF52832, on SDK16.0.  I've recently discovered that not setting a timeout for sd_ble_gap_connect means the connection attempt cannot be gracefully cancelled.  So as the next best available solution, I've been testing using the timeout.  I noticed that if my connection attempt continued indefinitely, I wouldn't receive advertisements.  Now that I am setting a 10 second timeout when i call sd_ble_gap_connect, I see that I start receiving advertisements again after 10 seconds.  That tells me the timeout is actually happening.  But I don't get the BLE_GAP_EVT_TIMEOUT.  When I set this timeout for normal scanning, I do get this timeout.  I also get connected and disconnected events, so it's not as if I don't have the event handler registered.

What is very odd is that if I have this timeout set in my global struct for scan parameters, and use this struct in both scanning setup and sd_ble_gap_connect, I get BLE_GAP_EVT_TIMEOUT with p_gap_evt->params.timeout.src == BLE_GAP_TIMEOUT_SRC_SCAN, when the connection attempt occurs.  But this isn't a workable solution for me, as I don't want a timeout for scanning, only connecting.

Related