openFile gives "file is locked" error on Linux when creating a non-existing file
Harendra Kumar
harendra.kumar at gmail.com
Tue Oct 8 07:45:40 UTC 2024
On Tue, 8 Oct 2024 at 11:50, Viktor Dukhovni <ietf-dane at dukhovni.org> wrote:
> What sort of filesystem is "/tmp/fsevent_dir-.../watch-root" located in?
This happens on github Linux CI. Not sure which filesystem they are
using. Earlier I was wondering if something funny is happening in case
they are using NFS. But NFS usually causes issues due to caching of
directory entries if we are doing cross-node operations, here we are
on a single node and operations are not running in parallel (or that's
what I believe). I will remove the hspec layer from the tests to make
sure that the code is simpler and our understanding is correct.
I will also run the tests on circle-ci to check if the problem occurs
there. I have never seen this problem in testing this on a Linux
machine on AWS even if I ran the tests for days in a loop.
> Creating and closing a file in write mode from GHC:
>
> import System.IO
>
> main :: IO ()
> main = do
> putStrLn "Show time" >> hFlush stdout
> openFile "/tmp/foo.out" WriteMode >>= hClose
>
> translates on Linux to (strace):
>
> write(1, "Show time\n", 10) = 10
> openat(AT_FDCWD, "/tmp/foo.out", O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0666) = 6
> newfstatat(6, "", {st_mode=S_IFREG|0644, st_size=0, ...}, AT_EMPTY_PATH) = 0
> ftruncate(6, 0) = 0
> ioctl(6, TCGETS, 0x7ffd358412a0) = -1 ENOTTY (Inappropriate ioctl for device)
> close(6) = 0
>
> Nothing at all unusual happening here, so if the OS returns EBUSY,
> perhaps there's something interesting you can report about the state of
> that directory before file creation? Perhaps there's some filesystem or
> other kernel resource you're maxing out during the tests?
Is EBUSY errno getting translated to "file is locked" error here? In
that case there can be other possibilities, depending on the machine
or the file system. The error message should perhaps indicate other
possibilities here, something like "file may be locked, or the file
system is temporarily busy/unavailable".
Let me check the openFile code, how it is translating system errors to
user errors.
-harendra
More information about the ghc-devs
mailing list