thin-edge / thin-edge.io

The open edge framework for lightweight IoT devices
https://thin-edge.io
Apache License 2.0
222 stars 55 forks source link

c8y mapper panics with malformed registration messages #2986

Closed rina23q closed 1 month ago

rina23q commented 4 months ago

Describe the bug c8y mapper panics with this error.

thread 'tokio-runtime-worker' panicked at crates/core/tedge_api/src/store/pending_entity_store.rs:162:49:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
2024-07-09T16:23:02.121644225Z ERROR Runtime: Actor CumulocityMapper-9 has finished unsuccessfully: JoinError(JoinError::Panic(Id(28), ...))    

To Reproduce Run these commands in this order.

tedge mqtt pub -r 'te/device/child02//' '{"@type":"child-device"}'
tedge mqtt pub -r 'te/device/child02//' '{"@type":"service"}'
tedge mqtt pub -r 'te/device/child02//' '{"@type":"child-device"}'

Expected behavior No panic. This scenario, changing @type should be treated as an error.

Screenshots

Environment (please complete the following information):

Additional context

didier-wenzek commented 1 month ago

This issue is quite serious. Trying to reproduce the error, I ended in a state where the mapper fails to start, panicking at crates/core/tedge_api/src/store/pending_entity_store.rs:162:49.

  1. Sending a first tedge mqtt pub -r 'te/device/child02//' '{"@type":"child-device"}' is okay.
  2. When sending an unexpected type tedge mqtt pub -r 'te/device/child02//' '{"@type":"child-device"}' makes the mapper crazy, taking 100% cpu.
  3. If killed, the mapper fails then to restart.
  4. The c8y mapper successfully restarts only after the child type is erased with tedge mqtt pub -r 'te/device/child02//' ''.

Note: for some unknown reason, there is no /etc/tedge/device/inventory.json on my device.

rina23q commented 1 month ago

@didier-wenzek Thanks for reproducing and creating a PR. The behaviour that you described is exactly what I found.

Note: for some unknown reason, there is no /etc/tedge/device/inventory.json on my device.

inventory.json is not automatically created. Only when user wants to add fragments to c8y in a static way, the file is supposed to be created by user. Refer to this.

gligorisaev commented 1 month ago

I am not able to reproduce the bug, so it is solved