This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients izbyshev, koobs, rudolphf, vstinner, Владислав Ярмак
Date 2019-04-16.09:56:57
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
> ktrace shows that dup(0) succeeded but fstat(0) failed.

Aha, the problem is still the is_valid_fd() function:

    /* Prefer dup() over fstat(). fstat() can require input/output whereas
       dup() doesn't, there is a low risk of EMFILE/ENFILE at Python
       startup. */

The function has been fixed on macOS with:

#ifdef __APPLE__
    /* bpo-30225: On macOS Tiger, when stdout is redirected to a pipe
       and the other side of the pipe is closed, dup(1) succeed, whereas
       fstat(1, &st) fails with EBADF. Prefer fstat() over dup() to detect
       such error. */
    struct stat st;
    return (fstat(fd, &st) == 0);

I see two options:

* Only use dup() on platforms when we know that dup() is enough to detect corner cases: Linux and Windows
* Force usage of fstat() on FreeBSD... But what about OpenBSD, NetBSD and other BSD variants?

I wrote attached PR 12852 to only use dup() on Linux and Windows.
Date User Action Args
2019-04-16 09:56:57vstinnersetrecipients: + vstinner, koobs, izbyshev, rudolphf, Владислав Ярмак
2019-04-16 09:56:57vstinnersetmessageid: <>
2019-04-16 09:56:57vstinnerlinkissue32849 messages
2019-04-16 09:56:57vstinnercreate