astarte-platform / astarte

Core Astarte Repository
https://docs.astarte-platform.org/
Apache License 2.0
236 stars 45 forks source link

Binaryblob and datetime properties sent as incorrect types upon reconnection. #935

Open sorru94 opened 2 months ago

sorru94 commented 2 months ago

Upon reconnection, Astarte transmits incorrect BSON types for some server-owned properties.

This issue can be observed when setting a server property of the following types: datetime, datetimearray, binaryblob, binaryblobarray.

Assuming to set a property while the device is connected, the BSON data is correctly transmitted to the device. For example, assuming a datetime endpoint is used to set a property to the value 2024-03-11T09:34:36.000Z, the following BSON object is received by the device:

10 00 00 00 09 76 00 e0 2b dd 2c 8e 01 00 00 00 

Which in human readable form is:

{ "v": "2024-03-11T09:34:36.000Z" }

However, if the device is power cycled Astarte will transmit the following value for the same property to the device.

10 00 00 00 12 76 00 e0  2b dd 2c 8e 01 00 00 00

Which in human readable form is:

{ "v": 1710149676000 }

The difference being that upon reconnection the BSON contains a integer 64 instead of a datetime. This is similar for binary blobs which receive strings instead of binaries.