Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

readline: move pause to fix #5927 #5930

Closed
wants to merge 1 commit into from
Closed

readline: move pause to fix #5927 #5930

wants to merge 1 commit into from

Conversation

danielchatfield
Copy link

Pause should be called before _setRawMode to prevent things going wonky
in windows (see #5927).

(sorry for messing up first pull request)

@Nodejs-Jenkins
Copy link

Thank you for contributing this pull request! Here are a few pointers to make sure your submission will be considered for inclusion.

The following commiters were not found in the CLA:

  • Daniel Chatfield

You can fix all these things without opening another issue.

Please see CONTRIBUTING.md for more information

@danielchatfield
Copy link
Author

I've signed the CLA now, will the Jenkins bot automatically realise this?

@danielchatfield
Copy link
Author

I'm not sure why those 3 tests are failing as they seem very unrelated, perhaps someone can shed some light on it.

@trevnorris
Copy link

Don't worry about them.

@bnoordhuis
Copy link
Member

Looks okay to me but is it possible to add a regression test for this?

Also, can you reword the commit log a little? The first line should explain what changed and why. Don't reference the GH issue in it, do that by wrapping up the commit log with a Fixes #xxxx. on a separate line.

@danielchatfield
Copy link
Author

@bnoordhuis I have fixed the commit and added a regression test.

origSetRawMode.apply(this, arguments);
}

rl.close()
Copy link
Member

Choose a reason for hiding this comment

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

Style: missing semicolon.

@bnoordhuis
Copy link
Member

@danielchatfield Thanks.

The test is not quite what I had in mind but I'm willing to believe it's hard to test for when the test doesn't run in a real terminal (when you run make test or python tools/test.py simple.)

I'll have to ask you to redo the commit log again. It's important that it explains both what changed and why, i.e. what bug does it fix.

@piscisaureus Can you take a look at this?

@danielchatfield
Copy link
Author

Fixed the commit again to add the missing semi colon.

Move pause() before _setRawMode() in close()
Includes regression test
Fixes #5927

pause should be called with RawMode set to true, therefore in close()
the pause() should be before the setRawMode(false). This fixes a bug
where under windows 8 new instances of readline will not be able to
receive input until enter is pressed.
@danielchatfield
Copy link
Author

@bnoordhuis I tried faking terminal input but couldn't get the test to work without actually using the terminal. I've updated the commit message, I hope it is alright this time.

@bnoordhuis
Copy link
Member

It's close enough, I'll amend it when I land it. I was looking for something like "readline: fix windows tty stall, pause before setting raw mode" (though that probably doesn't fit in 50 characters.)

I'd still like for @piscisaureus to take a look.

@danielchatfield
Copy link
Author

@piscisaureus Have you had a chance to take a look yet?

@piscisaureus
Copy link

I'm sorry, this issue somehow slipped my attention.

This is the forgotten twin fix for f34f1e3.

The underlying issue is caused by a minor behavior change from windows 7 to windows 8. Prior to windows 8 libuv could "cancel" a line-buffered read by closing the console handle that the ReadConsole operation was called with. This trick no longer works in windows 8; the ReadConsole operation doesn't return until the user hits enter.

@jepickett is working on a libuv patch (joyent/libuv#877) that makes libuv cancel a line-buffered read by simulating an enter keypress instead.

However this patch to node is still good since now libuv doesn't have to start and immediately cancel a ReadConsome operation anymore.

Testing-wise, this is as good as it gets. Node doesn't offer an API for simulating key presses which is what would be needed to test this more thoroughly.

LGTM.

piscisaureus pushed a commit that referenced this pull request Aug 17, 2013
On windows, libuv will immediately make a `ReadConsole` call (in the
thread pool) when a 'flowing' `uv_tty_t` handle is switched to
line-buffered mode. That causes an immediate issue for some users,
since libuv can't cancel the `ReadConsole` operation on Windows 8 /
Server 2012 and up if the program switches back to raw mode later.

But even if this will be fixed in libuv at some point, it's better to
avoid the overhead of starting work in the thread pool and immediately
cancelling it afther that.

See also f34f1e3, where the same change is made for the opposite
flow, e.g. move `resume()` after `_setRawMode(true)`.

Fixes #5927

This is a backport of dfb0461 (see #5930) to the v0.10 branch.
piscisaureus pushed a commit that referenced this pull request Aug 17, 2013
On windows, libuv will immediately make a `ReadConsole` call (in the
thread pool) when a 'flowing' `uv_tty_t` handle is switched to
line-buffered mode. That causes an immediate issue for some users,
since libuv can't cancel the `ReadConsole` operation on Windows 8 /
Server 2012 and up if the program switches back to raw mode later.

But even if this will be fixed in libuv at some point, it's better to
avoid the overhead of starting work in the thread pool and immediately
cancelling it afther that.

See also f34f1e3, where the same change is made for the opposite
flow, e.g. move `resume()` after `_setRawMode(true)`.

Fixes #5927

This is a backport of dfb0461 (see #5930) to the v0.8 branch.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants