[Webhooks] corrupt data in multipart webhook response

We have found a particular situation under which multi-part data from a webhook response becomes corrupt. Specifically, if there is a delay in the main loop (few hundred milliseconds) after a chunk of data is received, followed by a (different, unrelated) particle.Publish() call, the next chunk of data received will be corrupted (strange characters in buffer). This situation only occurs when the system thread is enabled. We tested and observed it under versions 0.6.0 and 0.5.1 of the system firmware. The bug does not occur with only a delay and without the particle.Publish call, and appears to be sensitive to timing/delay with which the particle.Publish call occurs.

It is possibly related to problem described here, but copying immediately to a different buffer does not help our problem: System thread and subscribe with multipart reply

Do you have any suggestions for dealing with this issue? Thanks!

The reason for that is probably the shared publish/subscribe buffer.
A possible workaround might be a hold-off logic for the publish, once you got the first part of the webhook response, till you collected all data and only after that allow publishing again.

You could queue any held back publishes and then after you got the “Go!” again push them out one by one while keeping an eye on the publish rate limit.

Please check this PR: https://github.com/spark/firmware/pull/1246, it should fix the problem.

Update: already merged to develop.

3 Likes