Skip to content

bpo-30237: Output error when ReadConsole is canceled by CancelSynchronousIo. #7911

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

Merged
merged 9 commits into from
Jul 19, 2018

Conversation

ValeriyaSinevich
Copy link
Contributor

@ValeriyaSinevich ValeriyaSinevich commented Jun 25, 2018

Output error when ReadConsole is canceled by CancelSynchronousIo instead of crashing.

https://bugs.python.org/issue30237

SetLastError(0);
BOOL res = ReadConsoleW(handle, &buf[off], len, &n, NULL);

if (!res) {
err = GetLastError();
break;
}
if (n == (DWORD) - 1 && (err = GetLastError()) == ERROR_OPERATION_ABORTED) {
break;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. @zooba, does this need a test? It's an uncommon edge case that I discovered randomly while experimenting with CancelSynchronousIo.

@ValeriyaSinevich, FYI read_console_w and _PyOS_WindowsConsoleReadline are still broken per bpo-28166 when PyErr_CheckSignals returns 0, i.e. if it's not the main thread or the SIGINT handler doesn't raise. It's an easy fix in the same functions if you want to work on it. Just immediately continue to retry ReadConsoleW.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it needs a test - it's a narrow enough fix that we're very unlikely to regress it.

@@ -556,14 +556,18 @@ read_console_w(HANDLE handle, DWORD maxlen, DWORD *readlen) {
Py_BEGIN_ALLOW_THREADS
DWORD off = 0;
while (off < maxlen) {
DWORD n, len = min(maxlen - off, BUFSIZ);
DWORD n = (DWORD) - 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a style nit, but the spaces around the - here (and elsewhere) makes all of these much harder to read - they look like subtractions, rather than a cast. Please write them as (DWORD)-1

@zooba
Copy link
Member

zooba commented Jul 19, 2018

Thanks!

@zooba zooba merged commit ce75df3 into python:master Jul 19, 2018
@miss-islington
Copy link
Contributor

Thanks @ValeriyaSinevich for the PR, and @zooba for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry @ValeriyaSinevich and @zooba, I had trouble checking out the 3.6 backport branch.
Please backport using cherry_picker on command line.
cherry_picker ce75df3031c86b78311b1ad76c39c0b39d7d7424 3.6

@bedevere-bot
Copy link

GH-8342 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 19, 2018
…nousIo. (pythonGH-7911)

(cherry picked from commit ce75df3)

Co-authored-by: ValeriyaSinevich <[email protected]>
zooba pushed a commit to zooba/cpython that referenced this pull request Jul 19, 2018
@bedevere-bot
Copy link

GH-8343 is a backport of this pull request to the 3.6 branch.

zooba pushed a commit that referenced this pull request Jul 29, 2018
…nousIo. (GH-7911)

(cherry picked from commit ce75df3)

Co-authored-by: ValeriyaSinevich <[email protected]>
zooba added a commit that referenced this pull request Jul 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants