{"action":"closed","issue":{"url":"https://api.github.com/repos/hashicorp/nomad/issues/1357","repository_url":"https://api.github.com/repos/hashicorp/nomad","labels_url":"https://api.github.com/repos/hashicorp/nomad/issues/1357/labels{/name}","comments_url":"https://api.github.com/repos/hashicorp/nomad/issues/1357/comments","events_url":"https://api.github.com/repos/hashicorp/nomad/issues/1357/events","html_url":"https://github.com/hashicorp/nomad/issues/1357","id":162500000,"number":1357,"title":"safely write state files","user":{"login":"a86c6f7964","id":165381,"avatar_url":"https://avatars.githubusercontent.com/u/165381?v=3","gravatar_id":"","url":"https://api.github.com/users/a86c6f7964","html_url":"https://github.com/a86c6f7964","followers_url":"https://api.github.com/users/a86c6f7964/followers","following_url":"https://api.github.com/users/a86c6f7964/following{/other_user}","gists_url":"https://api.github.com/users/a86c6f7964/gists{/gist_id}","starred_url":"https://api.github.com/users/a86c6f7964/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/a86c6f7964/subscriptions","organizations_url":"https://api.github.com/users/a86c6f7964/orgs","repos_url":"https://api.github.com/users/a86c6f7964/repos","events_url":"https://api.github.com/users/a86c6f7964/events{/privacy}","received_events_url":"https://api.github.com/users/a86c6f7964/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/hashicorp/nomad/labels/bug","name":"bug","color":"f7c6c7"},{"url":"https://api.github.com/repos/hashicorp/nomad/labels/client","name":"client","color":"bfdadc"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-06-27T17:01:11Z","updated_at":"2016-06-27T23:51:46Z","closed_at":"2016-06-27T23:51:46Z","body":"Currently https://github.com/hashicorp/nomad/blob/7db2eb03c40ecb4dea100ffb1c60d019ff70dfb1/client/util.go#L88 is not writing files to disk safely.\r\n\r\nAccording to golang docs WriteFile https://golang.org/pkg/io/ioutil/#WriteFile will truncate a file that exists before writing to it.\r\n\r\nGiven that `setState` is getting called all over the place this introduces a whole bunch of potential states in history where the json state file is empty.\r\n\r\nThe code should write to a temp file and then mv the temp file over the existing file (which in unix can be an atomic operation) It is important that the temp file lives in the exact same directory as well, because it can only be somewhat assure to be atomic if it is just changing inode table entries."}}
{"actor":{"display_login":"diptanu"}}