[erlang-bugs] [erlang-questions] Recursive Heap Allocation

Joe Armstrong <>
Wed Jul 25 09:36:02 CEST 2012


It's a bug in the smp handling of io:format.

This program has similar behaviour

  -module(bug1).
  -compile(export_all).

  test(N) ->
          io:format("~p~n", [N]),
          test(N+1).

I  did this:

1 > spawn(fun() -> etop:start() end).
2> bug1:test(0).

You can see that user_drv global process is accumulating messages
faster than it can handle them.
It's in usr_drv:io_request/3.

As far as I'm aware io:format did have flow control so this shouldn't happen

I then changed the program to the following:

test(N) ->
    Len = process_info(whereis(user_drv),[message_queue_len]),
    io:format("~p ~p~n", [N, Len]),
    test(N+1).

The printout from this is weird - the length stays at zero for long
periods - then climbs linearly
up to some number like  180 or 169 then instantaneously goes back to zero

Now I ran with "erl -smp disable"

The counter stays at zero forever.

I think the I/O handling for smp erlang is buggy






On Mon, Jul 23, 2012 at 9:50 PM, Greg Martin <> wrote:
> I'm just learning erlang using Erlang R15B01 (erts-5.9.1) on Windows. I'm
> wondering why ipv4_addrs:test(ipv4_addrs:first()) leads to the crash below
> and how it can be called so that it doesn't. Thanks.
>
> {1,2,22,127}
> {1,2,22,128}
> {1,2,22,129}
> {1,2,22,130}
> {1,2,22,131}
> {1,2,22,132}
> {1,2,22,133}
> {1,2,22,134}
>
> Crash dump was written to: erl_crash.dump
> eheap_alloc: Cannot allocate 373662860 bytes of memory (of type "heap").
>
>
> Abnormal termination
>
>
> -module(ipv4_addrs).
>
> -export([first/0, next/1, test/1]).
>
> first()->
>         { 1,1,0,0 }.
>
> next( { 255, 255, 255, 255 } ) -> done;
> next( { 9, 255, 255, 255 } ) -> { 11, 0, 0, 0 };
> next( { 172, 15, 255, 255 } ) -> { 172, 32, 0, 0 };
> next( { 192, 167, 255, 255 } ) -> { 192, 169, 0, 0 };
> next( { First, 255, 255, 255 } ) -> { First + 1, 0, 0, 0 };
> next( { First, Second, 255, 255 } ) -> { First, Second + 1, 0, 0 };
> next( { First, Second, Third, 255 } ) -> { First, Second, Third + 1, 0 };
> next( { First, Second, Third, Fourth } ) -> { First, Second, Third, Fourth +
> 1 }.
>
> test(done) -> done;
> test(Addr) ->
>         io:format("~p~n", [Addr]),
>         Next = next(Addr),
>         test(Next).
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions


More information about the erlang-bugs mailing list