-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix write_to_file function #336
Fix write_to_file function #336
Conversation
Probably, because of a racing condition, sometimes the file was written into inconsistent state which breaks the configuration and the hardware-exporter service. After adding a file lock and detaching the permission from writting, the bug seems to be fixed Closes: canonical#305
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, overall LGTM. Need more information on os.chmod
part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably, because of a racing condition,
I feel like if we have race conditions where code is trying to write to the same file at the same time, then we should fix the source, not just add file locking. It may require a refactor to only write out the config from one place. It would be nice to do some more debugging and find the source of the race condition here.
I tested again and removing the lock file, but keeping the implementation seems to solve the issue. I didn't see in the logs more than one hook triggering the I'm not sure about the root cause. My guess is that I believe that keeping things simple and using more high level python functions are enough to solve the issue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for experimenting! It's nice that we can go with something even simpler than the previous implementation and solve the bug at the same time. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Legit
Probably because of the usage of low level functions, as for example
os.open
andos.fdopen
, it's harder to deal with buffering which can result into files with inconsistent content, which breaks the configuration and the hardware-exporter service.After adding using high level functions and make the code simpler, the bug seems to be fixed
Closes: #305