Skip to content

Commit 833b6d2

Browse files
weeTikecarlescufi
authored andcommitted
[nrf fromlist] Bluetooth: Host: Cancel pending deferred work on disconnect
This fixes an issue that occurred if deferred_work is queued by another procedure before we run bt_conn_set_state(BT_CONN_DISCONNECTED). bt_conn_set_state yields to the system work queue in bt_conn_tx_notify, and then deferred_work runs and handles the disconnected callbacks. bt_conn_set_state then enqueues another deferred_work which calls the disconnected callbacks again and causes an assert. k_work_cancel_delayable will clear queued deferred work when we call bt_conn_set_state(BT_CONN_DISCONNECTED), guaranteeing that the disconnect callbacks will only be called once. Upstream PR #: 82543 Signed-off-by: Timothy Keys <[email protected]>
1 parent bf4df4a commit 833b6d2

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

subsys/bluetooth/host/conn.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,11 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
12641264
*/
12651265
switch (old_state) {
12661266
case BT_CONN_DISCONNECT_COMPLETE:
1267+
/* Any previously scheduled deferred work now becomes invalid
1268+
* so cancel it here, before we yield to tx thread.
1269+
*/
1270+
k_work_cancel_delayable(&conn->deferred_work);
1271+
12671272
bt_conn_tx_notify(conn, true);
12681273

12691274
bt_conn_reset_rx_state(conn);

0 commit comments

Comments
 (0)