[erlang-bugs] Crash when piping stdout to 'head'?

Mikael Pettersson mikpelinux@REDACTED
Mon May 4 06:35:39 CEST 2015


Eric Dahl writes:
 > I'm relatively new to erlang but ran across a weird issue which seems like
 > a bug. When I redirect the output to 'head -20', it causes the VM to crash.
 > Some other types of pipes are fine though.
 > 
 > I've encountered this initially on FreeBSD 10.1 with Erlang/OTP 17 but also
 > reproduced on Ubuntu 14.04 with Erlang R16B03
 > 
 > Minimal test case below:
 > 
 > $ cat redirection_test.erl
 > -module(redirection_test).
 > -export([start/0]).
 > 
 > f(0) -> 0;
 > f(N) -> io:format("~p ~n", [N]), f(N-1).
 > 
 > start() -> io:format("~p ~n", [f(100)]).
 > $ erlc redirection_test.erl
 > $ erl -noinput -s redirection_test -s init stop  | head -20
 > 100
 > 99
 > ...
 > 84
 > 83
 > 82
 > 81
 > 
 > Crash dump was written to: erl_crash.dump
 > init terminating in do_boot ()
 > $ uname -a
 > Linux erlang-test 3.13.0-43-generic #72-Ubuntu SMP Mon Dec 8 19:35:06 UTC
 > 2014 x86_64 x86_64 x86_64 GNU/Linux
 > $ erl --version
 > Erlang R16B03 (erts-5.10.4) [source] [64-bit] [async-threads:10]
 > [kernel-poll:false]
 > 
 > Eshell V5.10.4  (abort with ^G)
 > 
 > 
 > Thanks,
 > Eric

I'm not so sure this is a bug.

head -20 will close the pipe after consuming 20 lines from it.  Standard Unix
behaviour is to send a SIGPIPE signal to a process that writes to a closed pipe,
and unless caught or ignored that kills the process.  It looks like the Erlang
VM ignores SIGPIPE, so the write will instead fail with EPIPE.  Presumably
something in the call chain considers that a fatal error and terminates the VM.

Unless there is documentation to the effect that the VM is supposed to handle
this use case, I don't think this is a bug.

/Mikael



More information about the erlang-bugs mailing list