Author izbyshev
Recipients izbyshev, koobs, rudolphf, vstinner
Date 2018-02-20.00:43:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1519087383.46.0.467229070634.issue32849@psf.upfronthosting.co.za>
In-reply-to
Content
OK, never mind with the test. I've finally got to a FreeBSD box and reproduced the problem. It has to do with 'revoke' feature of *BSD. When revoke is called on a terminal device (as part of logout process, for example), all descriptors associated with it are invalidated. They can be dup'ed, but any I/O (including fstat) will fail with EBADF. The attached 'repro.c' demonstrates the same behavior as Python in your ktrace log.

# sleep 5; ./repro >&err.txt &
# exit
(login again)
# cat err.txt
isatty: Inappropriate ioctl for device
dup ok: 3
fstat: Bad file descriptor

So it seems that in your case the parent of your Python processes passed a descriptor referring to the terminal as fd 0, and then terminal got revoked at some point. People have stumbled on that, for example, https://bitbucket.org/tildeslash/monit/issues/649/init_env-fails-if-open-2-returns-an

As for Python, it seems OK to fix it as in #30225 since the fd is unusable for I/O anyway. I think that we can even drop dup-based validation from is_valid_fd() since there is a corner case for Linux too: if a descriptor opened with O_PATH inherited as a standard one, dup() will succeed but fstat() will fail in kernels before 3.6. And we do fstat() almost immediately after is_valid_fd() to get blksize, so the dup-based optimization doesn't seem worth the trouble.

Victor, do you have an opinion on that?
History
Date User Action Args
2018-02-20 00:43:03izbyshevsetrecipients: + izbyshev, vstinner, koobs, rudolphf
2018-02-20 00:43:03izbyshevsetmessageid: <1519087383.46.0.467229070634.issue32849@psf.upfronthosting.co.za>
2018-02-20 00:43:03izbyshevlinkissue32849 messages
2018-02-20 00:43:03izbyshevcreate