nerves-hub / nerves_hub_link

Connect devices to NervesHub via a Phoenix channel
https://hex.pm/packages/nerves_hub_link
Apache License 2.0
36 stars 18 forks source link

Apply backpressure to downloader on slow updates #202

Closed fhunleth closed 4 months ago

fhunleth commented 4 months ago

It's possible for the firmware download to be faster than fwup can write to eMMC or MicroSD. This causes the message queue to the update manager to balloon as data starts queuing up in route to fwup. On a device without much extra memory, this can be a cause of the following error:

04:14:26.957 [warn] __vm_enough_memory: pid: 87, comm: erts_sched_1, not enough memory for the allocation

This commit makes the asynchronous downloader updates synchronous so fwup can push back when the writes are time consuming. The backpressure results in the TCP receive buffers filling and eventually the download slowing.

fhunleth commented 4 months ago

I have this as draft since I've only run the unit tests. @ringlej and @abelino might be able to test it on a device that runs into the out of memory error.

fhunleth commented 4 months ago

See https://github.com/nerves-hub/nerves_hub_link_common/pull/35 for what was actually tested. @ringlej is using the maint_v1 branch.

oestrich commented 4 months ago

There's something not quite right with this on a real device. I need to keep poking at it before we merge

oestrich commented 4 months ago

The issue was something else and this seems to have the intended effect of not being noticeable on real devices :shipit: