shimmeringbee / controller

Implementation of home automation controller (a.k.a hub and gateway), initially focusing on Zigbee devices, written in Go.

Home Page:https://shimmeringbee.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Saved JSON state can be corrupted

pwood opened this issue · comments

For Any ZDA or ZStack saved configuration, it appears that it can be wiped out with a 0 byte JSON file. This seems to occur with no errors in logs - it only seems to happen during a shutdown. It's possible (given the frequency of saving) that a shutdown of the controller can result in corrupt configuration.

Consider approaches to avoid this:

  • Shifting saving to some kind of safe goroutine.
  • Save as file.new, rename file.json to file.old, rename file.new to file to json. rm file.old on completion (or keep history?)

This is particularily bad if zstack is corrupted as the IEEE<->NetworkAddress mapping is lost. ZDA will at least rediscover and attempt to reenumerate (though likely to fail on fiddly end devices).

This was addressed a with the recent mqtt merge, new file is saved out to a different file initially and then renamed. Old file is kept until process is completed.