0

I encountered an cowboy error

Ranch listener api_resource had connection process started with cowboy_protocol:start_link/4 at <0.1822.0> exit with reason: enomem#012

In the request handler, I'm interacting with another vendor's tts platform, via erlang port(c language). The first tts command to the port succeeded, I can got 1M bytes data, the second tts command to the port is sent to the port successfully, but then the cowboy process terminated immediatedly with the error message above.

I've tried to raise erlang vm's stack size, heap size, binary virtual heap size, and os's stack size, no help.

Any suggestion is appreciated, thanks.

code:

tts(Port, Params, Text) ->
    case call_port(Port, {'set_tts_params', Params}) of
        {'error', _}=Error -> Error;
        _ -> slice_tts(Port, slice_text(Text), <<>>)
    end.

slice_tts(_Port, [], Acc) ->
    lager:debug("tts over"),
    {'ok', <<"RIFF", (byte_size(Acc)+36):32, "WAVE", "fmt ", 16:32,
            1:16, 1:16, 16000:32, 32000:32, 2:16, 16:16,
            "data", (byte_size(Acc)):32, Acc/binary>>};

slice_tts(Port, [Text|Others], Acc) ->
    lager:debug("ttsing ~p bytes", [byte_size(Text)]),
    case call_port(Port, {'tts', Text}) of
        {'error', _}=Error -> Error;
        {'ok', Data} -> slice_tts(Port, Others, <<Acc/binary, Data/binary>>)
    end.
Raptor
  • 53,206
  • 45
  • 230
  • 366
jxiewei
  • 68
  • 6
  • `enomem` looks like running out of memory, which is hard to do in Erlang. I would suspect port. Ports are separate OS processes, so Erlang VM does not report memory used by ports. Try using `htop` to check, if it is port or ErlangVM, which eats the memory. – tkowal Oct 21 '14 at 07:41
  • @tkowal, thanks for the suggestion. I've checked htop output, erlang port process is not consuming much memory, there's still free memory in system. Furthur, if it's oom in port process, in the request handler we should get a 'EXIT' signal, other than enomem. – jxiewei Oct 22 '14 at 00:36
  • Finally, I found it. The port program used a library provided by the tts vendor, which used printf for debugging, so erlang vm received some unexpected message from port with very very large length indicatior, faiing the erlamgn vm allocator. I didn't know this because I never tried to run it as a standalone program. It's revealed until I strace the beam process. – jxiewei Oct 23 '14 at 07:51

0 Answers0