Skip to content

Conversation

simensrostad
Copy link
Contributor

@simensrostad simensrostad commented Oct 4, 2025

If location is cancelled during Wi-Fi search, the semaphore
blocking the location positioning workqueue is not released due to
k_sem_reset() being used instead of k_sem_give(). This prevents
subsequent location requests to start Wi-Fi scans.
This commit changes k_sem_reset() to k_sem_give() and adds a test
for this scenario.

LRCS-343

@simensrostad simensrostad requested a review from a team as a code owner October 4, 2025 10:12
@NordicBuilder NordicBuilder added the changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. label Oct 4, 2025
@simensrostad
Copy link
Contributor Author

Test still needs som massaging

@NordicBuilder
Copy link
Contributor

NordicBuilder commented Oct 4, 2025

CI Information

To view the history of this post, clich the 'edited' button above
Build number: 3

Inputs:

Sources:

sdk-nrf: PR head: c892b0d7674d18d99c000b1ef9ae4ce318cb1e5d

more details

sdk-nrf:

PR head: c892b0d7674d18d99c000b1ef9ae4ce318cb1e5d
merge base: ba0efe33df43ba6753f854abf631508d9211124a
target head (main): 9002fe1c0798c2895356b8513d561761ac30ef20
Diff

Github labels

Enabled Name Description
ci-disabled Disable the ci execution
ci-all-test Run all of ci, no test spec filtering will be done
ci-force-downstream Force execution of downstream even if twister fails
ci-run-twister Force run twister
ci-run-zephyr-twister Force run zephyr twister
List of changed files detected by CI (2)
lib
│  ├── location
│  │  │ scan_wifi.c
tests
│  ├── lib
│  │  ├── location
│  │  │  ├── src
│  │  │  │  │ location_test.c

Outputs:

Toolchain

Version: a7529a11f4
Build docker image: docker-dtr.nordicsemi.no/sw-production/ncs-build:a7529a11f4_bba2ea5f2e

Test Spec & Results: ✅ Success; ❌ Failure; 🟠 Queued; 🟡 Progress; ◻️ Skipped; ⚠️ Quarantine

  • ◻️ Toolchain - Skipped: existing toolchain is used
  • ❌ Build twister
    • sdk-nrf test count: 259
  • ❌ Integration tests
    • ❌ test-fw-nrfconnect-nrf-iot_cloud
    • ❌ test-fw-nrfconnect-nrf_lrcs_mosh
    • ❌ test-fw-nrfconnect-nrf_lrcs_positioning
    • ⚠️ test-fw-nrfconnect-nrf_lrcs_mosh
    • ⚠️ test-fw-nrfconnect-nrf_lrcs_positioning
Disabled integration tests
    • desktop52_verification
    • test-fw-nrfconnect-apps
    • test-fw-nrfconnect-ble_mesh
    • test-fw-nrfconnect-ble_samples
    • test-fw-nrfconnect-chip
    • test-fw-nrfconnect-fem
    • test-fw-nrfconnect-nfc
    • test-fw-nrfconnect-nrf-iot_libmodem-nrf
    • test-fw-nrfconnect-nrf-iot_lwm2m
    • test-fw-nrfconnect-nrf-iot_samples
    • test-fw-nrfconnect-nrf-iot_serial_lte_modem
    • test-fw-nrfconnect-nrf-iot_thingy91
    • test-fw-nrfconnect-nrf-iot_zephyr_lwm2m
    • test-fw-nrfconnect-nrf_crypto
    • test-fw-nrfconnect-proprietary_esb
    • test-fw-nrfconnect-ps-main
    • test-fw-nrfconnect-rpc
    • test-fw-nrfconnect-rs
    • test-fw-nrfconnect-tfm
    • test-fw-nrfconnect-thread-main
    • test-low-level
    • test-sdk-audio
    • test-sdk-dfu
    • test-sdk-find-my
    • test-sdk-mcuboot
    • test-sdk-pmic-samples
    • test-sdk-wifi
    • test-secdom-samples-public

Note: This message is automatically posted and updated by the CI

If location is cancelled during Wi-Fi search, the semaphore
blocking the location positioning workqueue is not released due to
k_sem_reset() being used instead of k_sem_give(). This prevents
subsequent location requests to start Wi-Fi scans.
This commit changes k_sem_reset() to k_sem_give() and adds a test
for this scenario.

Signed-off-by: Simen S. Røstad <[email protected]>
@simensrostad simensrostad changed the title lib: location: Fix Wi-Fi scan fallback mechanism lib: location: Use k_sem_give() when cancelling Wi-Fi location Oct 4, 2025
@simensrostad simensrostad added bug Something isn't working and removed changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. labels Oct 4, 2025
@simensrostad simensrostad requested a review from a team October 4, 2025 10:58
Copy link

github-actions bot commented Oct 4, 2025

You can find the documentation preview for this PR here.

/* Next time location is requested, the Wi-Fi scan semaphore should be available again
* and scan can be started again.
*/
__cmock_net_mgmt_NET_REQUEST_WIFI_SCAN_ExpectAndReturn(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test doesn't pass. You need to do this here too:
net_mgmt_NET_REQUEST_WIFI_SCAN_occurred = false;

The change will make this test pass but the state information is "wrong" within the library so there are some later tests that will fail likely because there is a pending WiFi scan ongoing.

Also, it would be nice that the test would succeed with the change to k_sem_give from k_sem_reset, and fail without it. I don't think that's the case now.

{
if (scan_wifi_ready != NULL) {
k_sem_reset(scan_wifi_ready);
k_sem_give(scan_wifi_ready);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a log which would show a scenario that this fixes. I can imagine what it fixes but I think we would need to fix the caller side. We are likely doing operations that we shouldn't do after the location request has been cancelled, such as taking the semaphore for waiting for Wi-Fi scan results.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found some logs from Jira.
k_sem_give makes things a little better although k_sem_reset is more appropriate in cancel operations in general. In this case, k_sem_take is not interested in the return value which is why k_sem_give happens to work better.

We can merge this once the test uses similar timing as the original problem. However, we would need additional investigation on whether method_cloud_location_positioning_work_fn still has some issues.

#if defined(CONFIG_LOCATION_METHOD_WIFI_NET_IF_UPDOWN)
ret = scan_wifi_startup_interface(wifi_iface);
if (ret) {
LOG_ERR("Failed to start Wi-Fi interface: %d", ret);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a duplicate log to what scan_wifi_startup_interface logs, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working DNM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants