{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/14491","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/14491/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/14491/comments","events_url":"https://api.github.com/repos/golang/go/issues/14491/events","html_url":"https://github.com/golang/go/issues/14491","id":136066467,"number":14491,"title":"io/ioutil: WriteFile does not write content to file","user":{"login":"TheHippo","id":199056,"avatar_url":"https://avatars.githubusercontent.com/u/199056?v=3","gravatar_id":"","url":"https://api.github.com/users/TheHippo","html_url":"https://github.com/TheHippo","followers_url":"https://api.github.com/users/TheHippo/followers","following_url":"https://api.github.com/users/TheHippo/following{/other_user}","gists_url":"https://api.github.com/users/TheHippo/gists{/gist_id}","starred_url":"https://api.github.com/users/TheHippo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TheHippo/subscriptions","organizations_url":"https://api.github.com/users/TheHippo/orgs","repos_url":"https://api.github.com/users/TheHippo/repos","events_url":"https://api.github.com/users/TheHippo/events{/privacy}","received_events_url":"https://api.github.com/users/TheHippo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/golang/go/milestones/31","html_url":"https://github.com/golang/go/milestones/Go1.7","labels_url":"https://api.github.com/repos/golang/go/milestones/31/labels","id":1414133,"number":31,"title":"Go1.7","description":"","creator":{"login":"bradfitz","id":2621,"avatar_url":"https://avatars.githubusercontent.com/u/2621?v=3","gravatar_id":"","url":"https://api.github.com/users/bradfitz","html_url":"https://github.com/bradfitz","followers_url":"https://api.github.com/users/bradfitz/followers","following_url":"https://api.github.com/users/bradfitz/following{/other_user}","gists_url":"https://api.github.com/users/bradfitz/gists{/gist_id}","starred_url":"https://api.github.com/users/bradfitz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bradfitz/subscriptions","organizations_url":"https://api.github.com/users/bradfitz/orgs","repos_url":"https://api.github.com/users/bradfitz/repos","events_url":"https://api.github.com/users/bradfitz/events{/privacy}","received_events_url":"https://api.github.com/users/bradfitz/received_events","type":"User","site_admin":false},"open_issues":276,"closed_issues":169,"state":"open","created_at":"2015-11-16T16:57:07Z","updated_at":"2016-04-02T02:19:00Z","due_on":"2016-07-31T07:00:00Z","closed_at":null},"comments":8,"created_at":"2016-02-24T13:48:44Z","updated_at":"2016-04-02T08:11:05Z","closed_at":null,"body":"Using Go 1.5.3 on Linux/amd64:\r\n\r\nWriting a file like:\r\n\r\n```go\r\nerr := ioutil.WriteFile(\"temp\", []byte(\"foo\"), 0644)\r\nif err != nil {\r\n\t// error handling\r\n}\r\n// read \"temp\"\r\n```\r\n\r\nReading the file content of `temp` immediately after writing it sometimes indicates the content hasn't been written to the file. Looking at the source code of [`WriteFile`](https://golang.org/src/io/ioutil/ioutil.go?s=2520:2588#L66) it seems like a call to `Sync()` is missing.\r\n\r\nP.S.: Tested with larger content."},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/204671109","html_url":"https://github.com/golang/go/issues/14491#issuecomment-204671109","issue_url":"https://api.github.com/repos/golang/go/issues/14491","id":204671109,"user":{"login":"dotwilbert","id":12401718,"avatar_url":"https://avatars.githubusercontent.com/u/12401718?v=3","gravatar_id":"","url":"https://api.github.com/users/dotwilbert","html_url":"https://github.com/dotwilbert","followers_url":"https://api.github.com/users/dotwilbert/followers","following_url":"https://api.github.com/users/dotwilbert/following{/other_user}","gists_url":"https://api.github.com/users/dotwilbert/gists{/gist_id}","starred_url":"https://api.github.com/users/dotwilbert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotwilbert/subscriptions","organizations_url":"https://api.github.com/users/dotwilbert/orgs","repos_url":"https://api.github.com/users/dotwilbert/repos","events_url":"https://api.github.com/users/dotwilbert/events{/privacy}","received_events_url":"https://api.github.com/users/dotwilbert/received_events","type":"User","site_admin":false},"created_at":"2016-04-02T08:11:05Z","updated_at":"2016-04-02T08:11:05Z","body":"I ran into the same issue on 3.19.0-32-generic x86_64 GNU/Linux. Linux Mint Rosa 17.3, based on Ubuntu 14.04.3 LTS. \r\n\r\nMy code parses logfiles and for testing writes each hit to a file in the file system: During a test run I got this:\r\n````\r\npanic: stat febtest1/DOC00004649.json: no such file or directory\r\n\r\ngoroutine 57570 [running]:\r\npanic(0x546060, 0xc828c591b0)\r\n\t/usr/local/go/src/runtime/panic.go:464 +0x3e6\r\nworkers/hits2elasticlogweb.(*HitFileStorage).Store(0xc82001e420, 0x7f7d4b5e0080, 0xc828956480, 0x0, 0x0)\r\n\t/home/wvandepieterman/Projects/Development/idea-workspace/log-processing/src/workers/hits2elasticlogweb/hitfilestorage.go:243 +0x4dd\r\nworkers/hits2elasticlogweb.processHit(0xc82000ef50, 0xc828956480, 0xc82431b080, 0x7f7d4b624450, 0xc82001e420)\r\n\t/home/wvandepieterman/Projects/Development/idea-workspace/log-processing/src/workers/hits2elasticlogweb/hitworker.go:146 +0x15d\r\ncreated by workers/hits2elasticlogweb.(*worker).start\r\n\t/home/wvandepieterman/Projects/Development/idea-workspace/log-processing/src/workers/hits2elasticlogweb/hits2elasticlogweb.go:100 +0x94c\r\n````\r\nCode responsible for the panic:\r\n````{.numberLines startFrom=\"233\"}\r\n233\tif update {\r\n234\t\tioutil.WriteFile(hfs.Name+string(os.PathSeparator)+id+`.json`, h.ToJSON(true), 0644)\r\n235\t} else {\r\n236\t\thc := new(Hit)\r\n237\t\t*hc = *h.(*Hit)\r\n238\t\thc.Id = id\r\n239\t\tioutil.WriteFile(hfs.Name+string(os.PathSeparator)+id+`.json`, hc.ToJSON(true), 0644)\r\n240\t}\r\n241\tistat, err := os.Stat(hfs.Name + string(os.PathSeparator) + id + `.json`)\r\n242\tif err != nil {\r\n243\t\tpanic(err.Error())\r\n244\t}\r\n````\r\n\r\nImmediately after writing the file, I stat it to get the size. Cop out I know, but it demonstrates the point TheHippo is making. \r\n\r\nLooking at it a few seconds later:\r\n````\r\n$ ls -ltr febtest1/DOC00004649.json \r\n-rw-r--r-- 1 wvandepieterman wvandepieterman 27887 Apr  2 00:36 febtest1/DOC00004649.json\r\n````\r\n\r\nIf I'm allowed an opinion, I think a utility method WriteFile should guarantee that the file exists after it has completed and thus should call Sync."}}