-
Notifications
You must be signed in to change notification settings - Fork 3k
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
io:get_line/1 cannot read cyrillic input on Windows with -noshell #8113
Comments
This is a known limitation/bug of the current implementation: https://github.com/erlang/otp/blob/OTP-26.2.2/erts/emulator/nifs/common/prim_tty_nif.c#L425-L427 If anyone has any tips on how to solve this problem feel free to help out. My current idea is to disallow migration from The gist of the issue is that we need to be able to go from line-mode to character-mode when reading from stdin. This means that if we use ReadFile in blocking mode, we will loose input when switching as it cannot be interrupted. So we use ReadFile in overlapped mode, but then Unicode does not work :( |
I see, thanks. @garazdawi, do you mean we lose intermediate input that you type but do not press enter? Or any input? For what is worth, it was never possible to type into |
You will loose any input until enter is pressed the first time after switching. So if you start iex with |
I see, perhaps in IEx we can start with |
I was thinking a bit more about this issue and maybe it would be possible to fix this if we update |
I am not sure how much these are related but "lazy reads" sound interesting to me because Erlang buffers all IO, even when shell is disabled. Compare this:
Because the Ruby program did not read anything, it is left in the buffer and then sent to the shell once the Ruby program terminates. In Erlang's case, all IO is buffered:
This leads to issues such as |
@garazdawi do you think this is related to #7621? If we fix one, we would fix both? |
Maybe. It depends a bit on what is triggering the interrupt in #7621. I’m planning to try to at least do a prototype for this in the next month or so now that 27 is finally released. |
I did a prototype for lazy reads, but I hit a snag... today the Erlang emulator will terminate if stdin is closed. Unfortunately it is rather hard to detect that stdin has been closed (that I can find) without reading from it, maybe I can do something creative with poll+POLLHUP on Unix and PeekNamedPipe on Windows. |
@garazdawi in my experience, most programming languages do not terminate when stdin is closed. I happen to run into this because Erlang ports close stdin, but since most runtimes do not terminate, they may leave zombie processes. Would it be an option to move the termination logic to the Erlang code, such as the Erlang shell, since that's the one reading input in a loop? So the shell still terminates, but those running |
Yeah, we are a bit different here (and in many other places...). We could possibly update I'll tinker around a bit with POLLHUP and PeekNamedPipe after my summer holiday and see if I can get that to work. Since the original problem was with Windows and switching from cooked to raw mode, then maybe I'll just focus on making Windows lazy and leave Unix as is for now. |
Just realized that using POLLHUP/PeekNamedPipe cannot work as we would end up spinning checking it if there is unread data on stdin but it is not closed... So the remaining options that I can see right now are:
A potential compromise is to change Doing the compromise would solve the problem on Windows when we want to switch from cooked ( Anyway, I'll get back to this after summer. |
FWIW, all of these options work for me. If there is an option for lazy reads, I would probably enable that by default in Elixir, and that may be less work for everyone! Thanks. |
Fixed in #8962 |
Describe the bug
Take the following program
foo.erl
:And then:
Once we typed "Привет" as input, it printed the wrong output. When I uncommented
erlang:display/1
, I could see that the issue is that we are reading the wrong input. We got the following bytes:But we expected:
Affected versions
Erlang/OTP 26.2. The reporter also tried the Windows installer provided by pull request #8103 with the same results.
Additional context
This issue was originally submitted here: elixir-lang/elixir#13301
To quote the reporter:
The text was updated successfully, but these errors were encountered: