News for hackers. Stuff that matters.
Re:POSIX close(2) is broken by swah on Saturday December 17, 2011 @07:51AM (#3364150)
What about checking how language implementations solve this for their 'closes' ?
Re:POSIX close(2) is broken by viraptor on Saturday December 17, 2011 @08:34AM (#3364198)
If you mean different other languages, that's interesting... Python seems to be completely oblivious to the issue and signals (Modules/_io/fileio.c internal_close() and others). There is SA_RESTART added if possible in Modules/faulthandler.c - but I'm not sure what conditions activate it.
Re:POSIX close(2) is broken by saurik on Sunday December 18, 2011 @10:49AM (#3366795)
Yeah. This can be a serious issue, for the record. It is difficult for me to come up with an experience that has made me quite as angry as calling urllib.urlopen().read() in a highly-contended program (Apache2 mpm_worker) and getting an EINTR exception bubbled all the way up to the top... I mean, what did they expect I do: retry the entire HTTP fetch? ;P

I finally switched to mpm_event, which caused me to no longer get signals constantly, but until then I was seriously running a patched copy of Python to work around this issue; an issue, by the way, which was reported at the beginning of 2007, and only fixed midway through 2010. :(

http://bugs.python.org/issue1628205

The general idea, however, is that if you are using a low-level primitive, one that nigh unto maps directly to a system call (as opposed to urlopen ;P), then you actually "want" (supposedly) EINTR to not be handled for you, as it might be your intention to use it to do something valuable (just as you might from a C program).

Re:POSIX close(2) is broken by __david__ on Saturday December 17, 2011 @02:38PM (#3364929)
Perl seems to do this (PerlIOUnix_close() in perlio.c)[1]:

    while (PerlLIO_close(fd) != 0) {
        if (errno != EINTR) {
            code = -1;
            break;
        }
        /* EINTR */
        if (PL_sig_pending && S_perlio_async_run(aTHX_ f))
            return -1;
    }

[1] https://github.com/mirrors/perl/blob/be48bbe8d671b6841c3ec7c...
Re:POSIX close(2) is broken by swah on Saturday December 17, 2011 @11:24AM (#3364476)
Sorry for the confusion - but yes, I meant languages implemented in C or C++ (Java, Factor, Python..)
Re:POSIX close(2) is broken by nknight on Saturday December 17, 2011 @08:23AM (#3364188)
I assume you're talking about dynamic languages like Python or Ruby. It's common for underlying system characteristics to leak through the abstractions, so something like this isn't necessarily "handled".

In CPython's case, as far as I can tell, it uses bare, unchecked close() calls, and just assumes they succeed.

(It does, however, provide an interface for dealing with signals, and one of the capabilities, as of 2.6, is to specify whether system calls will restart. See some discussion on SA_RESTART elsewhere in these comments.)