barakwei / ParticlePapertrail

Papertrail logging handler for Particle platforms
MIT License
13 stars 4 forks source link

Using network commands in log handler is not recommended #11

Open nzottmann opened 4 years ago

nzottmann commented 4 years ago

This log handler is sending udp packets in the log handler function: https://github.com/barakwei/ParticlePapertrail/blob/ab2a0836cc3343c85d156539dd3ae1bc12452ce3/src/papertrail.cpp#L28

Using network functions in the log handler function is not recommended:

I would recommend not doing anything that takes any time or can block from the log handler. This includes publishing, network, and any shared resource calls like SPI. https://community.particle.io/t/udp-or-particle-publish-in-log-handler-causing-freeze-with-system-thread/56826/4

Using this log handler in combination with SYSTEM_THREAD(ENABLED) can cause freezes on 3rd gen Devices, as described in the Particle forum thread linked above.

To solve this, the logs could be saved to a buffer and the network functions moved to the main loop, as suggested and implemented by @rickkas7 in https://github.com/rickkas7/SdCardLogHandlerRK