Skip to content

Erlang/OTP 26 write to stdout hangs in latin1 encoding on Windows #7459

@lukaszsamson

Description

@lukaszsamson

Describe the bug
After changing standard_io encoding to latin1 all writes to the output device hang.

To Reproduce

Run from windows command prompt

erl -noshell -eval "Path = os:find_executable('erl'), Port1 = erlang:open_port({spawn_executable, Path}, [binary, {args, ['-noshell', '-kernel', 'standard_io_encoding', 'latin1', '-eval', \"io:setopts(standard_io, [{encoding, latin1}]), io:format('duπa~n', []), erlang:halt()\"]}, exit_status]), receive {Port1, {data, A}} -> io:fwrite(A, []) after 2000 -> io:fwrite('nothing~n') end, erlang:halt()"

Result on windows

nothing

Expected behavior
Should print

du\x{3C0}a

it works correctly on OTP 25 both windows and *nix, and on OTP 26.0.2 on *nix

Affected versions
OTP 26.0.2

Additional context

This bug was tricky to track as it hangs only with a spawned process. If the same code is run directly from cmd shell it works correctly

erl -noshell -kernel standard_io_encoding latin1 -eval "io:setopts(standard_io, [{encoding, latin1}]), io:format('duπa~n', []), erlang:halt()"

prints

du\x{3C0}a

This bug breaks ElixirLS on windows elixir-lsp/elixir-ls#927

Possibly this is a regression of #7261 once fixed in 2bbeed3. The original script from that bug as well as a modified one hangs as well

-module(foo).
-compile(export_all).

run() ->
  io:put_chars("START\n"),

  open_port(
    {spawn_executable, os:find_executable("erl")},
    [exit_status, binary,
     {args, ["-noshell", "-kernel", "standard_io_encoding", "latin1", "-eval", "io:setopts(standard_io, [{encoding, latin1}]), io:write('teπt'), erlang:halt()."]}]
  ),

  loop().

loop() ->
  receive
    {_, {data, Data}} ->
      io:put_chars(Data),
      loop();

    {_, {exit_status, _}} ->
      erlang:halt()
  end.

Related to #7230, #7384

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue is reported as a bugteam:VMAssigned to OTP team VM

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions