Description
runtime.setsig supports calling sigaction(2) with the SA_RESTART
flag, which on OS X causes several system calls to be restarted when they would otherwise return EINTR
. In particular, open(2) is one of these, but only for "slow devices" and not regular files. I don't have direct evidence, but I believe this is because on OS X an open of a regular file can't usually block in a way that can be interrupted.
I see that SA_RESTART
is generally used for Go signal handlers: the default handlers all use it, and sigenable sets it. (The only exceptions appear to be SIGPIPE
and SIGABRT
). From this I conclude that it's intended that os.OpenFile not leak EINTR
out to the caller. I've never seen a retry loop around os.OpenFile, so this would make sense.
However, it seems on OS X open(2) of a file can be interrupted if the file is on a fuse file system. This came up for me when using os/exec.Command in parallel with opening a file backed by fuse. When the command completes the thread calling open(2) would sometimes receive SIGCHLD, causing errors like this:
open /var/folders/00/0mb18000h01000cxqpysvccm002jc5/T/fs_test474101889/foo: interrupted system call
Am I correct in assuming that os.OpenFile is not intended to leak EINTR
so that users don't need to call in a loop? If so, should it be modified to contain an internal retry loop?