[erlang-bugs] io:format causes whole Erlang VM to hang on slow stdout

Marek Majkowski majek04@REDACTED
Thu Jul 7 16:57:23 CEST 2011


Erlang VM hangs if no one is picking up data from stdout. Or in other words:
io:format causes a blocking writev() system call from within a main process. If
writev() hangs - whole erlang vm hangs.

See the attached testcase:

mkfifo b
./erlang-stdout-hangs.erl > b
## the program won't run until we start listeninig from the fifo
## so in new console:
cat b

You should be able to see 'ping' messages flowing.
After a while, suspend cat, by CONTROL+Z. Erlang will continue
printing "ping" for a while, until fifo buffer fills. When fifo buffer fills,
the whole erlang VM will stop. Strace proves that the main thread is blocked:

writev(1, [{"", 0}, {"erlang sucks<<\"payloadpayloadpay"..., 96}], 2) = ?
ERESTARTSYS (To be restarted)

Although the test program disables smp (-smp disable), it's possible
to block the smp erlang - you just need to do io:format from multiple
erlang processes.

Tested on R14B03.

Cheers,
  Marek Majkowski
-------------- next part --------------
A non-text attachment was scrubbed...
Name: erlang-stdout-hangs.erl
Type: text/x-erlang
Size: 384 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20110707/ed607fff/attachment.bin>


More information about the erlang-bugs mailing list