Skip to content
Snippets Groups Projects
Commit cafe9834 authored by Simon Marlow's avatar Simon Marlow Committed by Ben Gamari
Browse files

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
parent 4bfff7a5
No related branches found
No related tags found
No related merge requests found
......@@ -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-}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment