To avoid these problems I am using an overlay FS (just reads from flash and writes to memory) and after a reboot all changes are gone. That might not be suitable for everyone but works great for stuff like mqtt brokers or devices which pull their configuration on boot.