UniversalDevicesInc / Polyglot

Polyglot Open Source
MIT License
24 stars 2 forks source link

Interrupted polyglot now have zero size config file. #6

Closed jimboca closed 8 years ago

jimboca commented 8 years ago

I control-C'ed Polyglot, then when I tried to start it again I got json errors, which I traced down to an empty config file. My guess is that it was writing the config when I interrupted?

pi@rpi2:~/dev/Polyglot $ ls -l config/configuration.json -rw------- 1 pi pi 0 Mar 12 16:50 config/configuration.json

mjwesterhof commented 8 years ago

This problem was noted earlier on the forum by someone - so it would seem that it's more probable than it seems at first glance at the code. I suspect buffering may be making it more likely to happen -- but the fix is to write to a temp file, then use rename (mv) operations, which are atomic and thus won't leave us without a valid config file.

Also, the code should check to see if its really necessary to rewrite the config file in the first place - it's almost always going to be identical to the one on-disk. Excessive writes will wear out an SD card on the RPi.

Einstein42 commented 8 years ago

I'm going to work on some of this stuff today. Has anyone started work on this yet? I'll take it on today if not.

jimboca commented 8 years ago

I've not looked at it yet. Thanks!

On Sun, Mar 13, 2016, 8:10 AM James notifications@github.com wrote:

I'm going to work on some of this stuff today. Has anyone started work on this yet? I'll take it on today if not.

— Reply to this email directly or view it on GitHub https://github.com/UniversalDevicesInc/Polyglot/issues/6#issuecomment-195974410 .

jimboca commented 8 years ago

Also, I think it happened to me because I hit control c twice in a row. Which interrupted the write it tries to do before exiting from trapping the first signal.

Einstein42 commented 8 years ago

No problem. I'll work on something.

Einstein42 commented 8 years ago

Updated this with latest pull request. Please verify and merge.

jimboca commented 8 years ago

I'm not sure if my issue was caused by this change, but now every time I kill and restart polyglot I lose my configuration? I kill polyglot, check my configuration.json and all node servers are still there, then I start polyglot again and the node servers are not in the configuration.json anymore? It still has the correct ISY ip address and password, so I'm not loosing all configuration, just the node servers. Can you verify this is not an issue for you?

mjwesterhof commented 8 years ago

What I'm seeing in my installation are the same symptoms -- the node servers all go away on restart. The problem does not seem to be that the config file is damaged on shutdown -- the file is complete whenever I check. The problem is that the configuration is damaged on startup. So something has changed with the logic there that has resulted in the node servers portion of the configuration to become empty (all else is the same in the data written to the config file).

Einstein42 commented 8 years ago

Interesting. I will investigate.

On Sun, Mar 20, 2016 at 7:17 PM, Mike Westerhof notifications@github.com wrote:

What I'm seeing in my installation are the same symptoms -- the node servers all go away on restart. The problem does not seem to be that the config file is damaged on shutdown -- the file is complete whenever I check. The problem is that the configuration is damaged on startup. So something has changed with the logic there that has resulted in the node servers portion of the configuration to become empty (all else is the same in the data written to the config file).

— You are receiving this because you modified the open/close state. Reply to this email directly or view it on GitHub https://github.com/UniversalDevicesInc/Polyglot/issues/6#issuecomment-199067902

mjwesterhof commented 8 years ago

I backed down to commit 1eca52161cedf2460427406bf566faae5f01fd32 (the last one committed by Einstein42 regarding to this issue) -- works fine. So I suspect that it is more recent -- I'm suspicious of the changes made to nodeserver_api.py -- but I cannot bisect this any further because the node restructuring code is not working from the first commit on this branch up to the last couple... :(

I'll update the issue for the for the internal node structure with this info too.

jimboca commented 8 years ago

The second change in this commit seemed a little suspicous https://github.com/UniversalDevicesInc/Polyglot/commit/839351decbae39005b1c793858d6a2235769b5aa It specifically moved the nodeservers.load

jimboca commented 8 years ago

Looks like a different change caused the issue.

Einstein42 commented 8 years ago

Jim you are correct, simply put the cart before the horse on the update config. I've tested with the HUE and restarted 10 times in a row and had the hue poly start every time with no errors. Control-c'd repeatedly and tried to break it. All successful. Merging to development