summaryrefslogtreecommitdiff
path: root/libraries/base/GHC/IO
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2017-12-11 12:56:09 -0500
committerBen Gamari <ben@smart-cactus.org>2017-12-11 13:02:52 -0500
commitcafe98345cb5d4b11f2059d60d2f20e976ef4f2a (patch)
tree9073483304e5148247fbcb1f7d85f586718f1b6e /libraries/base/GHC/IO
parent4bfff7a507b5807736e9c6ce9814a9cfa60faeff (diff)
downloadhaskell-cafe98345cb5d4b11f2059d60d2f20e976ef4f2a.tar.gz
Always use the safe open() call
open() can sometimes take a long time, for example on NFS or FUSE filesystems. We recently had a case where open() was taking multiple seconds to return for a (presumably overloaded) FUSE filesystem, which blocked GC and caused severe issues. Test Plan: validate Reviewers: niteria, bgamari, nh2, hvr, erikd Reviewed By: bgamari Subscribers: rwbarton, thomie, carter GHC Trac Issues: #13296 Differential Revision: https://phabricator.haskell.org/D4239
Diffstat (limited to 'libraries/base/GHC/IO')
-rw-r--r--libraries/base/GHC/IO/FD.hs12
1 files changed, 4 insertions, 8 deletions
diff --git a/libraries/base/GHC/IO/FD.hs b/libraries/base/GHC/IO/FD.hs
index a7a34c1bc4..4a4f063219 100644
--- a/libraries/base/GHC/IO/FD.hs
+++ b/libraries/base/GHC/IO/FD.hs
@@ -179,14 +179,10 @@ openFile filepath iomode non_blocking =
| otherwise = oflags2
in do
- -- the old implementation had a complicated series of three opens,
- -- which is perhaps because we have to be careful not to open
- -- directories. However, the man pages I've read say that open()
- -- always returns EISDIR if the file is a directory and was opened
- -- for writing, so I think we're ok with a single open() here...
- fd <- throwErrnoIfMinus1Retry "openFile"
- (if non_blocking then c_open f oflags 0o666
- else c_safe_open f oflags 0o666)
+ -- NB. always use a safe open(), because we don't know whether open()
+ -- will be fast or not. It can be slow on NFS and FUSE filesystems,
+ -- for example.
+ fd <- throwErrnoIfMinus1Retry "openFile" $ c_safe_open f oflags 0o666
(fD,fd_type) <- mkFD fd iomode Nothing{-no stat-}
False{-not a socket-}