Skip to content

bluetooth: services: ras: fix RRSP disconnect deadlock - #30805

Open
martintv wants to merge 1 commit into
nrfconnect:mainfrom
martintv:fixing_deadlock_in_ras_rrsp
Open

bluetooth: services: ras: fix RRSP disconnect deadlock#30805
martintv wants to merge 1 commit into
nrfconnect:mainfrom
martintv:fixing_deadlock_in_ras_rrsp

Conversation

@martintv

Copy link
Copy Markdown
Contributor

Defer instance teardown to rrsp_wq instead of calling k_work_queue_drain() from the connection disconnect callback.

Blocking sysworkq on rrsp_wq could deadlock when send_data_work was waiting for att_pool buffers that are only recycled on sysworkq. Stop new RRSP work after disconnect with a disconnecting flag.

@martintv
martintv requested a review from a team as a code owner August 20, 2026 08:40
@NordicBuilder
NordicBuilder requested a review from a team August 20, 2026 08:40
@martintv
martintv force-pushed the fixing_deadlock_in_ras_rrsp branch from b422f8b to d426c32 Compare August 20, 2026 08:46
@alexstanoev-nordic
alexstanoev-nordic self-requested a review August 20, 2026 08:46
@NordicBuilder

NordicBuilder commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

CI Information

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

Inputs:

Sources:

sdk-nrf: PR head: a3d949abdc332f50584b45b655f2ba80a9000578

more details

sdk-nrf:

PR head: a3d949abdc332f50584b45b655f2ba80a9000578
merge base: 15b36cb022b160e024277df4fbd3bbe606051960
target head (main): 9a67d4cefeb7789d9e30d7e142a820a80bb06b4b
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
ci-run-draft Run CI on draft pull requests
List of changed files detected by CI (2)
include
│  ├── bluetooth
│  │  ├── services
│  │  │  │ ras.h
subsys
│  ├── bluetooth
│  │  ├── services
│  │  │  ├── ras
│  │  │  │  ├── rrsp
│  │  │  │  │  │ ras_rrsp.c

Outputs:

Toolchain

Version: e214c2a47c
Build docker image: docker-dtr.nordicsemi.no/sw-production/ncs-build:e214c2a47c_a140d687bb

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

  • ◻️ Toolchain - Skipped: existing toolchain is used
  • ✅ Build twister
    • sdk-nrf test count: 624
  • ✅ Integration tests
    • ✅ desktop52_verification
    • ✅ test-fw-nrfconnect-apps_nrfdesktop
    • ✅ test_ble_nrf_config
    • ✅ test-fw-nrfconnect-ble_samples
    • ✅ test-sdk-find-my
Disabled integration tests
    • test-fw-nrfconnect-nrf_lrcs_mosh
    • test-fw-nrfconnect-nrf_lrcs_positioning
    • test-fw-nrfconnect-apps
    • test-fw-nrfconnect-ble_mesh
    • 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_zephyr_lwm2m
    • test-fw-nrfconnect-nrf_crypto
    • 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-mcuboot
    • test-sdk-wifi
    • test-sdk-wifi-net

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Defers RRSP teardown to its work queue to prevent disconnect deadlocks.

Changes:

  • Adds asynchronous teardown and disconnect-state guards.
  • Documents delayed instance reuse.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
subsys/bluetooth/services/ras/rrsp/ras_rrsp.c Implements deferred teardown and work suppression.
include/bluetooth/services/ras.h Documents asynchronous teardown behavior.
Suppressed comments (2)

subsys/bluetooth/services/ras/rrsp/ras_rrsp.c:151

  • Setting conn to NULL makes this slot allocatable while its teardown_work handler is still executing. A concurrent allocation for another connection can select the slot, memset it, and reinitialize the same running k_work; it can also overwrite instance state before this handler returns. Keep pool availability synchronized with work completion, for example by initializing work objects once and managing slot state separately under a lock.
	bt_conn_unref(rrsp->conn);
	rrsp->conn = NULL;
	rrsp->disconnecting = false;

subsys/bluetooth/services/ras/rrsp/ras_rrsp.c:173

  • The disconnected instance continues occupying its pool slot until this low-priority queue reaches teardown. With auto-allocation enabled and CONFIG_BT_RAS_RRSP_MAX_ACTIVE_CONN < CONFIG_BT_MAX_CONN, a new connection arriving in that interval gets -ENOMEM from connected()'s unchecked allocation and is never assigned an RRSP instance. Add an allocation handoff/retry after teardown or release/reserve pool capacity synchronously.
	(void)k_work_submit_to_queue(&rrsp_wq, &rrsp->teardown_work);

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +139 to +143
(void)k_work_cancel(&rrsp->send_data_work);
(void)k_work_cancel(&rrsp->rascp_work);
(void)k_work_cancel(&rrsp->status_work);

if (rrsp->active_buf) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this can be dismissed, as the timer is stopped in bt_ras_rrsp_free before the teardown work is submitted to the queue.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I moved stopping of the timer to the teardown, that will catch the case where rd_segment_send starts the timer it gets preempted by the disconnected callback too, because the teardown will happen after rd_segment_send complets.

Comment on lines +143 to +144
if (rrsp->active_buf) {
bt_ras_rd_buffer_release(rrsp->active_buf);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this comment wsa good, i removed this code, bt_ras_rd_buffer_release wasnt called in cleanup before this commit either . so this was a mistake to add here.

@github-actions

Copy link
Copy Markdown

You can find the documentation preview for this PR here.

@KyraLengfeld KyraLengfeld left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Generally looks good, and I think the one copilot comment can be dismissed (commented there), but the possibly overwritten buffer concern should be checked. (I haven't looked at the file copilot is quoting there, let me know if I should).

Jenkins is also failing please have a look at it. (wfh today and the vpn app is refusing me right now, so cannot check what)

Also, this seems known-issue worthy, but would leave it to @alexstanoev-nordic how it is handled for services. (In any case a label needs to be added).

Comment on lines +139 to +143
(void)k_work_cancel(&rrsp->send_data_work);
(void)k_work_cancel(&rrsp->rascp_work);
(void)k_work_cancel(&rrsp->status_work);

if (rrsp->active_buf) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this can be dismissed, as the timer is stopped in bt_ras_rrsp_free before the teardown work is submitted to the queue.

Defer instance teardown to rrsp_wq instead of calling
k_work_queue_drain() from the connection disconnect callback.

Blocking sysworkq on rrsp_wq could deadlock when send_data_work was
waiting for att_pool buffers that are only recycled on sysworkq.
Stop new RRSP work after disconnect with a disconnecting flag.

Signed-off-by: Martin Tverdal <martin.tverdal@nordicsemi.no>
@martintv
martintv force-pushed the fixing_deadlock_in_ras_rrsp branch from d426c32 to a3d949a Compare August 20, 2026 12:57
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

Successfully merging this pull request may close these issues.

4 participants