Skip to content

Commit b3ffaf4

Browse files
weeTikekartben
authored andcommitted
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. Signed-off-by: Timothy Keys <[email protected]>
1 parent 4c96cbb commit b3ffaf4

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
@@ -1254,6 +1254,11 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
12541254
*/
12551255
switch (old_state) {
12561256
case BT_CONN_DISCONNECT_COMPLETE:
1257+
/* Any previously scheduled deferred work now becomes invalid
1258+
* so cancel it here, before we yield to tx thread.
1259+
*/
1260+
k_work_cancel_delayable(&conn->deferred_work);
1261+
12571262
bt_conn_tx_notify(conn, true);
12581263

12591264
bt_conn_reset_rx_state(conn);

0 commit comments

Comments
 (0)