From 3eb7a8bde845c3f9e9373d922322124e800085a3 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sat, 11 May 2019 15:03:10 -0700 Subject: [PATCH] Sync before Close() to avoid random I/O (#7638) --- cmd/posix.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/posix.go b/cmd/posix.go index f8978764a..3bc837fe9 100644 --- a/cmd/posix.go +++ b/cmd/posix.go @@ -1087,7 +1087,7 @@ func (s *posix) CreateFile(volume, path string, fileSize int64, r io.Reader) (er return err } - w, err := disk.OpenFileDirectIO(filePath, os.O_CREATE|os.O_WRONLY|os.O_EXCL|os.O_SYNC, 0666) + w, err := disk.OpenFileDirectIO(filePath, os.O_CREATE|os.O_WRONLY|os.O_EXCL, 0666) if err != nil { switch { case os.IsPermission(err): @@ -1100,6 +1100,7 @@ func (s *posix) CreateFile(volume, path string, fileSize int64, r io.Reader) (er return err } } + defer w.Sync() // Sync before close. defer w.Close() var e error