Typed characters are mis-ordered when CPU usage is high

Takashi Yano takashi.yano@nifty.ne.jp
Fri Mar 18 04:23:35 GMT 2022


On Thu, 17 Mar 2022 20:40:15 +0200
Orgad Shaneh wrote:
> On Fri, Mar 11, 2022 at 11:36 PM Takashi Yano <takashi.yano@nifty.ne.jp> wrote:
> > I looked into this problem and found the cause.
> > This seems to be due to a bug of fsync(). Cygwin's fsync()
> > flushes the console input buffer unlike linux.
> >
> > I will propose a patch for this issue.
> >
> > --
> > Takashi Yano <takashi.yano@nifty.ne.jp>
> 
> Thank you very much. Looks better now.
> 
> I'm sorry for nudging, but on msys2 I still get frequent mistypes when
> typing fast.
> 
> I (still) don't have a consistent reproduction, but if I get it
> correctly, it looks like one or more characters I type right when the
> prompt appears show up before the buffered characters.
> 
> For instance, I run git fetch, and while it is running I type git
> status, *sometimes* 1-2 characters "pop" to the left, so I get
> something like tgit satus.
> 
> I wasn't able to reproduce it with cygwin, but on msys2 (with cygwin
> 3.3 branch merged in) it happens to me all the time :/

Thansk for the report.

I cloned the msys2-runtime repository from
https://github.com/msys2/msys2-runtime
and applied patches in cygwin-3_3-branch against msys2-3_3_4-release
branch. The patches applied are listed in cygwin-3_3-branch-merged.log
attached. A few patches, which are not actually in cygwin-3_3-branch,
are also applied just for avoiding conflict easily.

However, I cannot reproduce your problem. Have you surely applied the
following patches especially important for this issue?

Could you please also check if the code of cons_master_thread() in
fhandler_console.cc exactly matches with cons_master_thread.cc attached?

commit 4d0721a66f94427fa14601d0c58a0762709b5bf2
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
Date:   Fri Feb 25 17:10:03 2022 +0900

    Cygwin: console: Prevent the order of typeahead input from swapped.

    - If a lot of keys are typed very quickly in the app which does
      not read console, the order of input keys in console input buffer
      occasionally swapped. Although this extremely rarely happens,
      is obviously a bug of cons_master_thread. This patch fixes the
      issue.

commit f48870148c7ebcaf8163b08a040d15ef048f4e94
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
Date:   Mon Feb 28 20:02:01 2022 +0900

    Cygwin: console: Improve the code to avoid typeahead key swapping.

    - The commit "Cygwin: console: Prevent the order of typeahead input
      from swapped." did not fully resolve the issue. If keys are typed
      during input buffer fix, the order of key event may be swapped.
      This patch fixes the issue again.

commit 6e872adb9f153ba0504c898a91ac8dcf0ed7e68a
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
Date:   Wed Mar 2 09:55:52 2022 +0900

    Cygwin: console: Prevent special keys processing from drop.

    - There was a potential risk to drop special key processing when
      process_input_messsage() is called intermittently. This patch
      fixes the issue.

commit d88768187a72662d1692ee279e7dea3e948d256e
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
Date:   Wed Mar 2 11:08:27 2022 +0900

    Cygwin: console: Fix a bug from comparison between int and DWORD.

commit cef38f41f2ce0510855bb4b872c7f6514f6deca5
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
Date:   Wed Mar 2 16:00:31 2022 +0900

    Cygwin: console, pty: Revamp the acquire/release_attach_mutex timing.

    - This patch revises the acquiring/releasing timing for attach_mutex
      to make the period in which it is being acquired shorter. Further,
      acquiring/releasing are added to where they are missing but needed.

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cygwin-3_3-branch-merged.log
Type: application/octet-stream
Size: 20665 bytes
Desc: not available
URL: <https://cygwin.com/pipermail/cygwin/attachments/20220318/a0f11c30/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cons_master_thread.cc
Type: text/x-c++src
Size: 5451 bytes
Desc: not available
URL: <https://cygwin.com/pipermail/cygwin/attachments/20220318/a0f11c30/attachment-0001.bin>


More information about the Cygwin mailing list