zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.86k stars 6.62k forks source link

Bluetooth pending tx packets assert on disable #54542

Closed ktaborowski closed 1 year ago

ktaborowski commented 1 year ago

Describe the bug Fatal error (assert) on disabling Bluetooth when a pending transaction (notification).

Please also mention any information which could help others to understand the problem you're facing:

To Reproduce Steps to reproduce the behavior: 1.checkout on https://github.com/ktaborowski/sdk-zephyr/tree/zephyrproject-bt-notify-and-disconnect

  1. cd zephyr/samples/bluetooth/peripheral
  2. west build -p -b nrf52840dk_nrf52840
  3. Connect nRF52840 DK board (PCA10056)
  4. west flash
  5. Subscribe to notification e.g. with nRF Connect App

nrfconnect_1_connect nrfconnect_2_service nrfconnect_3_notifications

  1. Wait a few seconds, device disconnects automatically

Expected behavior Device disconnects, no fault.

Impact We are facing the same issues in more complex application (prepared dumb sample for easy reproduction).

Logs and console output

*** Booting Zephyr OS build v3.3.0-rc2-1-gdf764c604062 ***
[00:00:00.420,410] <inf> fs_nvs: nvs_mount: 8 Sectors of 4096 bytes
[00:00:00.420,410] <inf> fs_nvs: nvs_mount: alloc wra: 0, ee8
[00:00:00.420,440] <inf> fs_nvs: nvs_mount: data wra: 0, 124
[00:00:00.422,668] <inf> bt_hci_core: hci_vs_init: HW Platform: Nordic Semiconductor (0x0002)
[00:00:00.422,698] <inf> bt_hci_core: hci_vs_init: HW Variant: nRF52x (0x0002)
[00:00:00.422,729] <inf> bt_hci_core: hci_vs_init: Firmware: Standard Bluetooth controller (0x00) Version 3.3 Build 0
[00:00:00.423,217] <inf> bt_hci_core: bt_init: No ID address. App must call settings_load()
Bluetooth initialized
[00:00:00.423,950] <inf> bt_hci_core: bt_dev_show_info: Identity: D1:D1:AE:D1:FB:7C (random)
[00:00:00.423,980] <inf> bt_hci_core: bt_dev_show_info: HCI: version 5.3 (0x0c) revision 0x0000, manufacturer 0x05f1
[00:00:00.424,041] <inf> bt_hci_core: bt_dev_show_info: LMP: version 5.3 (0x0c) subver 0xffff
Advertising successfully started
Indicate VND attr 0x2d8e8 (UUID 12345678-1234-5678-1234-56789abcdef1)
Updated MTU: TX: 23 RX: 23 bytes
Connected
Connection countdown 9
[00:01:55.439,727] <wrn> bt_gatt: gatt_notify: Device is not subscribed to characteristic
Notify fail (err=-22)
Connection countdown 8
[00:01:56.439,941] <wrn> bt_gatt: gatt_notify: Device is not subscribed to characteristic
Notify fail (err=-22)
Connection countdown 7
[00:01:57.440,155] <wrn> bt_gatt: gatt_notify: Device is not subscribed to characteristic
Notify fail (err=-22)
Connection countdown 6
[00:01:58.440,399] <wrn> bt_gatt: gatt_notify: Device is not subscribed to characteristic
Notify fail (err=-22)
Connection countdown 5
Connection countdown 4
Connection countdown 3
Connection countdown 2
Connection countdown 1
Connection countdown 0
ASSERTION FAIL [sys_slist_is_empty(&conn->tx_pending)] @ WEST_TOPDIR/zephyr/subsys/bluetooth/host/conn.c:740
    Pending TX packets
[00:02:04.442,657] <err> os: esf_dump: r0/a1:  0x00000004  r1/a2:  0x000002e4  r2/a3:  0x00000003
[00:02:04.442,687] <err> os: esf_dump: r3/a4:  0x20000e28 r12/ip:  0x200063c4 r14/lr:  0x0000af15
[00:02:04.442,687] <err> os: esf_dump:  xpsr:  0x41000000
[00:02:04.442,718] <err> os: esf_dump: Faulting instruction address (r15/pc): 0x000286fa
[00:02:04.442,749] <err> os: z_fatal_error: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0
[00:02:04.442,810] <err> os: z_fatal_error: Current thread: 0x20001b08 (unknown)
[00:02:04.528,015] <err> os: k_sys_fatal_error_handler: Halting system

Environment (please complete the following information):

nordicjm commented 1 year ago

Your code references a connection when it connects then never unrefs it

ktaborowski commented 1 year ago

Your code references a connection when it connects then never unrefs it

EDIT: unref added, unfortunately fault is still there

jori-nordic commented 1 year ago

@ktaborowski could you try the changes in https://github.com/zephyrproject-rtos/zephyr/pull/54651 and report if it fixes your issue?

ktaborowski commented 1 year ago

@ktaborowski could you try the changes in #54651 and report if it fixes your issue?

Yes, it fixed the issue. Thank you