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
tty issues when switching to raw mode on Windows #852
Comments
|
Sounds good to me! As for b), it looks quite complex, I'd got here if we have no other choice, I trust your judgement there. 👍 |
|
I know the CloseHandle() trick doesn't work since windows 8 any more (I'm not aware of any reliability issues with Windows 7 though) but as @orangemocha said, there aren't really any good alternative ways to cancel a line buffered read. Most of the time node got away with it by making sure to never start reading in line buffered mode in the first place; when we start up the repl just switch to raw mode before starting to read on stdin. But somehow every year or some somehow comes along and makes a change that reverses the order. I find this really an issue with open source (and node in particular) - institutional knowledge is lost so fast. All the subtle mistakes we made and fixed in the repl, url/path path parsing, module loading etc., are made again about every other release, and they will be made again, probably somewhere in the next 12 months, and things will break, and people will complain, and patches will be released, and the cycle will start all over. Anyway, that was a grumpy tangent. My advice would be to get rid of line buffered mode entirely. Who needs it anyway? |
|
Thanks for your insights Bert! |
|
Thanks for your input, @piscisaureus !
There might have always been a race condition there. Even if you just do The first line in that range triggers a line buffered read, with the following code path: ..and the last line cancels the read, in: The bug in Node started appearing much more frequently after a c-ares update. My best theory is that the c-ares update caused a change in the timing in Node's startup, in which turn causes the problematic side of the race condition to win the race more often. |
@piscisaureus I am not sure... is that realistic? Are you suggesting that most users don't read from stdin directly, but rather use the readline module? In any case, it would be a significant breaking change and it would have to go through some deprecation period. Re-implementing buffered line read in libuv in terms of raw mode would have to be motivated by the opportunity to emulate the unix behavior more closely. I gather from your feedback that is not a very useful goal. In any case, we'll need to land the hack to make ReadConsole return. A pull request is coming soon. |
Well, people read from stdin. But do people really read from the console in line buffered mode?
It is my sense that it's not a useful goal. But I don't know everything, so if there is evidence to the contrary I will change my opinion.
👍 |
|
The Windows 10 update coming some time later this year makes changes of some kind to the console subsystem (the background being the new Linux subsystem which at the very least needs Windows to be as good as a vt100, sigh). I don't know if this will manifest in any API-level changes (though the ability to use ANSI escape codes might be useful for output, at least) but it may make this
more feasible. Or it may not. |
While investigating nodejs/node#5384 and a host of related issues, we have discovered a few issues and incompatibilites with the current Windows implementation of tty in libuv.
After much investigation, we have identified two possible fixes:
Fix a) is much easier, and also the only fix of the two that would be admissible in Node LTS releases, so we are pursuing it first. It doesn’t address the second issue (pending line input getting lost when transitioning to raw mode), but again that seems less critical.
Regarding fix b), I wanted to first get your feedback on whether it would be desirable before deciding if we should attempt it. We would have the ability to emulate the Unix tty behavior more closely, and re-play any pending line input after switching to raw mode (fix issue 2). We would have to keep our own buffer and process arrow keys, backspace, etc.. Line history is implemented by ReadConsole, and doesn’t seem to have a counterpart in the Unix tty implementation. There are a few Node modules implementing history though, including the built-in readline module, so it might not be a bad thing to level this platform difference. The Unix tty also doesn’t handle arrow keys - they are returned as escape sequences. Again, we could consider emulating the same, which would probably also make it easier to implement. Would such behavior be desirable? It would have to be considered a breaking change on Windows.
cc @saghul @piscisaureus
The text was updated successfully, but these errors were encountered: