bpo-30237: Output error when ReadConsole is canceled by CancelSynchronousIo. (GH-7911)

(cherry picked from commit ce75df3031c86b78311b1ad76c39c0b39d7d7424)

Co-authored-by: ValeriyaSinevich <valeriya.sinevich@phystech.edu>
diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c
index b85c11b..4d3d695 100644
--- a/Modules/_io/winconsoleio.c
+++ b/Modules/_io/winconsoleio.c
@@ -556,7 +556,8 @@
     Py_BEGIN_ALLOW_THREADS
     DWORD off = 0;
     while (off < maxlen) {
-        DWORD n, len = min(maxlen - off, BUFSIZ);
+        DWORD n = (DWORD)-1; 
+        DWORD len = min(maxlen - off, BUFSIZ);
         SetLastError(0);
         BOOL res = ReadConsoleW(handle, &buf[off], len, &n, NULL);
 
@@ -564,6 +565,9 @@
             err = GetLastError();
             break;
         }
+        if (n == (DWORD)-1 && (err = GetLastError()) == ERROR_OPERATION_ABORTED) {
+            break;
+        }
         if (n == 0) {
             err = GetLastError();
             if (err != ERROR_OPERATION_ABORTED)