-
-
Notifications
You must be signed in to change notification settings - Fork 34.9k
bpo-34780: Fix potential hang during stdin initialization on Windows #9520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Fix hang on startup if stdin refers to a pipe with an outstanding concurrent | ||
| operation on Windows. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,7 +119,8 @@ file_PyObject_Print(PyObject *op, PyFileObject *f, int flags) | |
| static PyFileObject* | ||
| dircheck(PyFileObject* f) | ||
| { | ||
| #if defined(HAVE_FSTAT) && defined(S_IFDIR) && defined(EISDIR) | ||
| #if !defined(MS_WINDOWS) && defined(HAVE_FSTAT) && defined(S_IFDIR) && \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't open a directory via
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it's possible if we don't want to make If I may update the patch once there is a decision about fixing
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now I see your points here and above, but is there any reason to make
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My reasoning was that we can end up with an fd for a directory using PyWin32 and
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you, I understand your reasoning. A nitpick: we can still abuse import ctypes, msvcrt, subprocess, sys
h = ctypes.windll.kernel32.CreateFileA(
".",
0,
0,
0,
3, # OPEN_EXISTING
0x02000000, # FILE_FLAG_BACKUP_SEMANTICS
0,
)
fd = msvcrt.open_osfhandle(h, 0)
subprocess.check_call([sys.executable, '-c', 'import sys; sys.stdout.write("OK")'],
stdout=fd) The above prints the following: Personally, I'd either fix both |
||
| defined(EISDIR) | ||
| struct stat buf; | ||
| int res; | ||
| if (f->f_fp == NULL) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unlikely but still possible that
fdis a directory. For example, say the directory was opened withCreateFile(via ctypes, PyWin32, etc) and the file descriptor was opened withmsvcrt.open_osfhandle. Granted thefstatcheck has never worked on Windows, but we could actually make it work rather than skip it:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I considered that
fdcan refer to a directory, but I wasn't sure whether we should bother to fixdircheckin 2.7. I mentioned in the bug report that if we do want to fixdircheck, we may use 3.x approach, which is the same that you propose (in_Py_fstat_noraise). If I get more feedback suggesting to fixdircheck, I'll update the patch. Thank you!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This suggestion was only for this inline check in
os.fdopen. I don't thinkdircheckin fileobject.c should even be called on Windows.