Skip to content

Panic when using Thread #607

@l0nax

Description

@l0nax

Bug description

When using the experimental Thread module, the ESP32-C6 sometimes crashes.
Previously I wasn't able to connect to the WiFi, but after using ESP-IDF v5.2.x and creating an "IoT" network with PMF disabled the ESP now connects successfully.

Sometimes (by resetting the MCU over and over again) the OpenThread integration works as expected. But I only managed to get it into this state once.

  • Would you like to work on a fix? -> yes

To Reproduce

The related code & config can be found here: https://gitlab.com/l0nax/esp32c6-openthread-panic-bug-repro#

Please note that when using the master branch of this repository I receive a bunch of compilation errors which I did not manage to resolve:

error[E0432]: unresolved imports `crate::sys::otDnsTxtEntry`, `crate::sys::otSrpClientAddService`, `crate::sys::otSrpClientClearHostAndServices`, `crate::sys::otSrpClientClearService`, `crate::sys::otSrpClientEnableAutoStartMode`, `crate::sys::otSrpClientGetHostInfo`, `crate::sys::otSrpClientGetServerAddress`, `crate::sys::otSrpClientGetServices`, `crate::sys::otSrpClientHostInfo`, `crate::sys::otSrpClientIsAutoStartModeEnabled`, `crate::sys::otSrpClientIsRunning`, `crate::sys::otSrpClientItemState`, `crate::sys::otSrpClientItemState_OT_SRP_CLIENT_ITEM_STATE_ADDING`, `crate::sys::otSrpClientItemState_OT_SRP_CLIENT_ITEM_STATE_REFRESHING`, `crate::sys::otSrpClientItemState_OT_SRP_CLIENT_ITEM_STATE_REGISTERED`, `crate::sys::otSrpClientItemState_OT_SRP_CLIENT_ITEM_STATE_REMOVED`, `crate::sys::otSrpClientItemState_OT_SRP_CLIENT_ITEM_STATE_REMOVING`, `crate::sys::otSrpClientItemState_OT_SRP_CLIENT_ITEM_STATE_TO_ADD`, `crate::sys::otSrpClientItemState_OT_SRP_CLIENT_ITEM_STATE_TO_REFRESH`, `crate::sys::otSrpClientItemState_OT_SRP_CLIENT_ITEM_STATE_TO_REMOVE`, `crate::sys::otSrpClientRemoveHostAndServices`, `crate::sys::otSrpClientRemoveService`, `crate::sys::otSrpClientService`, `crate::sys::otSrpClientSetHostAddresses`, `crate::sys::otSrpClientSetHostName`, `crate::sys::otSrpClientStart`, `crate::sys::otSrpClientStop`
  --> /home/eb/.cargo/git/checkouts/esp-idf-svc-3846902cb7f9c731/3c7ce53/src/thread/srp.rs:10:39
   |
10 |     esp, esp_openthread_get_instance, otDnsTxtEntry, otError, otError_OT_ERROR_INVALID_ARGS,
   |                                       ^^^^^^^^^^^^^ no `otDnsTxtEntry` in `sys`
11 |     otError_OT_ERROR_NO_BUFS, otIp6Address, otIp6Address__bindgen_ty_1, otSrpClientAddService,
   |                                                                         ^^^^^^^^^^^^^^^^^^^^^ no `otSrpClientAddService` in `sys`
12 |     otSrpClientClearHostAndServices, otSrpClientClearService, otSrpClientEnableAutoStartMode,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `otSrpClientEnableAutoStartMode` in `sys`
   |     |                                |
   |     |                                no `otSrpClientClearService` in `sys`
   |     no `otSrpClientClearHostAndServices` in `sys`
13 |     otSrpClientGetHostInfo, otSrpClientGetServerAddress, otSrpClientGetServices,
   |     ^^^^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^^^^^ no `otSrpClientGetServices` in `sys`
   |     |                       |
   |     |                       no `otSrpClientGetServerAddress` in `sys`
   |     no `otSrpClientGetHostInfo` in `sys`
14 |     otSrpClientHostInfo, otSrpClientIsAutoStartModeEnabled, otSrpClientIsRunning,
   |     ^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^^^
   |     |                    |
   |     |                    no `otSrpClientIsAutoStartModeEnabled` in `sys`
   |     no `otSrpClientHostInfo` in `sys`
15 |     otSrpClientItemState, otSrpClientItemState_OT_SRP_CLIENT_ITEM_STATE_ADDING,
   |     ^^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16 |     otSrpClientItemState_OT_SRP_CLIENT_ITEM_STATE_REFRESHING,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17 |     otSrpClientItemState_OT_SRP_CLIENT_ITEM_STATE_REGISTERED,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18 |     otSrpClientItemState_OT_SRP_CLIENT_ITEM_STATE_REMOVED,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19 |     otSrpClientItemState_OT_SRP_CLIENT_ITEM_STATE_REMOVING,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20 |     otSrpClientItemState_OT_SRP_CLIENT_ITEM_STATE_TO_ADD,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21 |     otSrpClientItemState_OT_SRP_CLIENT_ITEM_STATE_TO_REFRESH,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22 |     otSrpClientItemState_OT_SRP_CLIENT_ITEM_STATE_TO_REMOVE, otSrpClientRemoveHostAndServices,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23 |     otSrpClientRemoveService, otSrpClientService, otSrpClientSetHostAddresses,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
24 |     otSrpClientSetHostName, otSrpClientStart, otSrpClientStop, EspError, ESP_ERR_INVALID_STATE,
   |     ^^^^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^

error[E0432]: unresolved imports `crate::sys::otSrpClientEnableAutoHostAddress`, `crate::sys::otSrpClientGetKeyLeaseInterval`, `crate::sys::otSrpClientGetLeaseInterval`, `crate::sys::otSrpClientGetTtl`, `crate::sys::otSrpClientSetKeyLeaseInterval`, `crate::sys::otSrpClientSetLeaseInterval`, `crate::sys::otSrpClientSetTtl`
  --> /home/eb/.cargo/git/checkouts/esp-idf-svc-3846902cb7f9c731/3c7ce53/src/thread/srp.rs:29:5
   |
29 |     otSrpClientEnableAutoHostAddress, otSrpClientGetKeyLeaseInterval, otSrpClientGetLeaseInterval,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `otSrpClientGetLeaseInterval` in `sys`
   |     |                                 |
   |     |                                 no `otSrpClientGetKeyLeaseInterval` in `sys`
   |     no `otSrpClientEnableAutoHostAddress` in `sys`
30 |     otSrpClientGetTtl, otSrpClientSetKeyLeaseInterval, otSrpClientSetLeaseInterval,
   |     ^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `otSrpClientSetLeaseInterval` in `sys`
   |     |                  |
   |     |                  no `otSrpClientSetKeyLeaseInterval` in `sys`
   |     no `otSrpClientGetTtl` in `sys`
31 |     otSrpClientSetTtl,
   |     ^^^^^^^^^^^^^^^^^ no `otSrpClientSetTtl` in `sys`

error: cannot find macro `debug` in this scope
    --> /home/eb/.cargo/git/checkouts/esp-idf-svc-3846902cb7f9c731/3c7ce53/src/thread.rs:1525:9
     |
1525 |         debug!("Border router initialized");
     |         ^^^^^
     |
help: consider importing this macro
     |
   6 + use log::debug;
     |

error: cannot find macro `debug` in this scope
    --> /home/eb/.cargo/git/checkouts/esp-idf-svc-3846902cb7f9c731/3c7ce53/src/thread.rs:1533:9
     |
1533 |         debug!("Border router deinitialized");
     |         ^^^^^
     |
help: consider importing this macro
     |
   6 + use log::debug;
     |

error[E0412]: cannot find type `otSrpClientHostInfo` in module `crate::sys`
   --> /home/eb/.cargo/git/checkouts/esp-idf-svc-3846902cb7f9c731/3c7ce53/src/thread/srp.rs:948:39
    |
948 |         host_info: *const crate::sys::otSrpClientHostInfo,
    |                                       ^^^^^^^^^^^^^^^^^^^ not found in `crate::sys`

error[E0412]: cannot find type `otSrpClientService` in module `crate::sys`
   --> /home/eb/.cargo/git/checkouts/esp-idf-svc-3846902cb7f9c731/3c7ce53/src/thread/srp.rs:949:38
    |
949 |         services: *const crate::sys::otSrpClientService,
    |                                      ^^^^^^^^^^^^^^^^^^ not found in `crate::sys`

error[E0412]: cannot find type `otSrpClientService` in module `crate::sys`
   --> /home/eb/.cargo/git/checkouts/esp-idf-svc-3846902cb7f9c731/3c7ce53/src/thread/srp.rs:950:46
    |
950 |         removed_services: *const crate::sys::otSrpClientService,
    |                                              ^^^^^^^^^^^^^^^^^^ not found in `crate::sys`

error[E0425]: cannot find function `otSrpClientSetCallback` in module `crate::sys`
    --> /home/eb/.cargo/git/checkouts/esp-idf-svc-3846902cb7f9c731/3c7ce53/src/thread.rs:1341:25
     |
1341 |             crate::sys::otSrpClientSetCallback(
     |                         ^^^^^^^^^^^^^^^^^^^^^^ not found in `crate::sys`

error[E0560]: struct `EspThread<'d, BorderRouter<N>>` has no field named `inner`
    --> /home/eb/.cargo/git/checkouts/esp-idf-svc-3846902cb7f9c731/3c7ce53/src/thread.rs:1728:13
     |
1728 |             inner: UnsafeCell::new(EspThreadInner::new(netif, BorderRouter(backbone_netif))),
     |             ^^^^^ `EspThread<'d, BorderRouter<N>>` does not have this field
     |
     = note: available fields are: `netif`, `mode`

error[E0433]: failed to resolve: use of undeclared type `EspThreadInner`
    --> /home/eb/.cargo/git/checkouts/esp-idf-svc-3846902cb7f9c731/3c7ce53/src/thread.rs:1728:36
     |
1728 |             inner: UnsafeCell::new(EspThreadInner::new(netif, BorderRouter(backbone_netif))),
     |                                    ^^^^^^^^^^^^^^ use of undeclared type `EspThreadInner`

error[E0061]: this function takes 3 arguments but 1 argument was supplied
    --> /home/eb/.cargo/git/checkouts/esp-idf-svc-3846902cb7f9c731/3c7ce53/src/thread.rs:1726:9
     |
1636 |   impl<'d, N> EspThread<'d, BorderRouter<N>>
     |               ------------------------------ this is the type of the `Self` literal
...
1726 |           Self::internal_init(Self {
     |  _________^^^^^^^^^^^^^^^^^^^-
1727 | |             driver,
1728 | |             inner: UnsafeCell::new(EspThreadInner::new(netif, BorderRouter(backbone_netif))),
1729 | |         })
     | |__________- two arguments of type `netif::EspNetif` and `BorderRouter<N>` are missing
     |
note: expected `ThreadDriver<'_, Host>`, found `EspThread<'_, BorderRouter<N>>`
    --> /home/eb/.cargo/git/checkouts/esp-idf-svc-3846902cb7f9c731/3c7ce53/src/thread.rs:1726:29
     |
1726 |           Self::internal_init(Self {
     |  _____________________________^
1727 | |             driver,
1728 | |             inner: UnsafeCell::new(EspThreadInner::new(netif, BorderRouter(backbone_netif))),
1729 | |         })
     | |_________^
     = note: expected struct `ThreadDriver<'_, Host>`
                found struct `EspThread<'d, BorderRouter<N>>`
note: associated function defined here
    --> /home/eb/.cargo/git/checkouts/esp-idf-svc-3846902cb7f9c731/3c7ce53/src/thread.rs:1877:8
     |
1877 |     fn internal_init(
     |        ^^^^^^^^^^^^^
1878 |         driver: ThreadDriver<'d, Host>,
     |         ------------------------------
1879 |         netif: EspNetif,
     |         ---------------
1880 |         mut mode: T,
     |         -----------
help: provide the arguments
     |
1726 -         Self::internal_init(Self {
1727 -             driver,
1728 -             inner: UnsafeCell::new(EspThreadInner::new(netif, BorderRouter(backbone_netif))),
1729 -         })
1726 +         Self::internal_init(/* ThreadDriver<'_, Host> */, /* netif::EspNetif */, /* BorderRouter<N> */)
     |

When upgrading to a newer ESP-IDF version, the behavior is almost the same but it panics because of an unknown event.
This is due to a new OpenThread event OPENTHREAD_EVENT_DATASET_CHANGED (https://github.com/espressif/esp-idf/blob/2044fba6e71422446986f9ae0909b1ab67e57815/components/openthread/include/esp_openthread_types.h#L49).

Logs:

[...]
I (4854) OPENTHREAD: Platform UDP bound to port 49153
I(4854) OPENTHREAD:[N] Mle-----------: Role disabled -> detached
I (4864) esp32c6_ble_wifi_credentials: [OT-Sub] Got: GotIpv6
I (4864) esp32c6_ble_wifi_credentials: [OT-Sub] Got: MulticastJoined
I (4874) esp32c6_ble_wifi_credentials: [OT-Sub] Got: MulticastJoined
I (4874) wifi:Set ps type: 2, coexist: 0

I (4894) esp32c6_ble_wifi_credentials: Thread Border Router initialized, now running...
I (4904) OPENTHREAD: Platform UDP bound to port 61631
I (4914) esp32c6_ble_wifi_credentials: [OT-Sub] Got: RoleChanged { current_role: Detached, previous_role: Disabled }
I (4914) OT_STATE: netif up
I (4914) esp32c6_ble_wifi_credentials: [OT-Sub] Got: IfUp

thread '<unnamed>' (2) panicked at /home/eb/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/esp-idf-svc-0.51.0/src/thread.rs:1831:18:
unknown event ID: 17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expected behavior

  • That the WiFi connects without running into the ESP_ERR_TIMEOUT problem over and over again, i.e. it can be used with a "normal" WiFi network.
  • The OpenThread integration can be used "stable", i.e., not crashing almost every time.

Environment

  • Crate (esp-idf-svc) version: v0.51.0
  • ESP-IDF branch or tag: v5.2.2, v5.2.5
  • Target device (MCU): esp32c6 (on the 'esp32-c6-devkitc-1' board)
  • OS: Arch Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions