WildernessLabs / Meadow_Issues

Public repo for bugs and issues with Meadow
15 stars 0 forks source link

Using VS2022 Debugger causes memory allocation failures #489

Open doingnz opened 9 months ago

doingnz commented 9 months ago

Describe the bug A simple sample application fails very soon after start when Debugging with VBS2022 Debugger.

Possibly when sending HealthMetrics to Meadow Cloud, but also in other situations when HealthMetrics are disabled.

Running from CLI with meadow app run is more reliable and a Release build from VS2022 also appears to be Ok.

The application run loop waits 10 seconds, does Garbage Collection and outputs TotalMemory in a while loop.

The problems appear to be an interaction with the debugger and events related to OTA/Cloud/network. During initialisation the application registers against the UpdateService, NTP events, Wifi Connect, Error and Disconnected events. The application registers 2 Cloud commands.

To Reproduce Steps to reproduce the behavior:

  1. Clone sample application here . Its currently under the Additional Samples folder.
  2. There is nothing in the application that requires the Clima platform.
  3. The Test app should run on any CCM or F7 Meadow. (edit the public class MeadowApp : App<F7CoreComputeV2>)
  4. Clone all the Meadow assemblies on the develop branch to folders at the same level as the 'Clima' folder.
  5. Edit the Clima\Source\Additional Samples\Azure\Clima_Azure_Demo\wifi.config.yaml file to add the Wifi SSID & PASSWORD
  6. Register the Meadow to the Meadow cloud if not already registered.
  7. First show the application runs OK in Release by building and deploying the Release version of the application from VS2022 or from the CLI.
  8. The application should connect to Wifi, get NTP, register to Meadow cloud and Update Service and then output TotalMemory every 10 seconds.
  9. Wait till to app is ready to accept commands, then test the application by sending a command from Meadow cloud which will display a countdown output to the stdout/logger. Optionally send the command more than once to see it continue sto work. command name: PingMeadowCommand arguments: { "Seconds": 10 }
  10. Stop and rebuild the Debug application.
  11. Launch with VS2022 Debugger, wait for the start up process to register for the services, and attempt to do the same PingMeadowCommand

Expected behavior The application should run when launched by VS2022 debugger without lock up of VS2022, no memory allocation errors, no pmutex '142' errors.

Screenshots Example output when launched with VS2022 Debugger

IP Address is 192.168.2.122
Adding UDP Logging ...
Run GetTotalMemory= 918560
Run GetTotalMemory= 954160
authentication successful. extracting token
authentication successful. extracting token
decrypting auth payload
decrypting auth payload
auth token successfully received
auth token successfully received
Run GetTotalMemory= 1041960
Updater State -> Connecting
Creating MQTT client options
Adding MQTT creds
Connecting MQTT client
making cloud log httprequest with json: {"eventId":10,"description":"device.health","measurements":{"health.cpu_temp_celsius":39.1538461538461,"health.memory_used":786968,"health.disk_space_used":13965983,"info.os_version":"1.8.0.0","info.coprocessor_os_version":"1.8.0.0"},"timestamp":"2024-02-27T10:14:39.919176+00:00"}
Could not allocate 1280 bytes
Could not allocate 4096 bytes
Could not allocate 4096 bytes
Could not allocate 4096 bytes

Developer tools (please complete the following information as best as you can):

Meadow:

Meadow by Wilderness Labs
Board Information
    Model: F7Micro
    Hardware version: F7CoreComputeV2
    Device name: MeadowOTA

Hardware Information
    Processor type: STM32F777IIK6
    ID: 2E-00-36-00-03-51-38-34-35-31-38-33
    Serial number: 336E316D3438
    Coprocessor type: ESP32
    MAC Address -
        WiFi: 4C:75:25:D5:26:E8

Firmware Versions
    OS: 1.8.0.0
    Runtime: 1.8.0.0
    Coprocessor: 1.8.0.0
    Protocol: 8

Additional context If you turn off HealthMetrics in app.config.yaml, then the Debug application may run for longer before it dies.

doingnz commented 9 months ago

Debugging is possible if BOTH HealthMetrics AND Update service are turned off in the app.config.yaml.