[erlang-questions] Diagnosing gen_server call timeouts

Max Lapshin max.lapshin@REDACTED
Fri Sep 20 02:45:09 CEST 2019


Copy paste from our video_frame.erl:


send_frame(Stream, #video_frame{content = Content, codec = Codec, flavor =
Flavor, dts = DTS} = Frame, SourceTag) when is_pid(Stream) ->
  Frame1 = case SourceTag of
    undefined -> Frame;
    _ -> Frame#video_frame{source = SourceTag}
  end,
  try gen_server:call(Stream, Frame1)
  catch
    exit:{normal, _} ->
      {error, stopped};
    exit:{noproc, _} ->
      {error, stopped};
    exit:{shutdown, _} ->
      {error, stopped};
    exit:{timeout, _}:Stack ->
      Dict = case process_info(Stream, dictionary) of
        {dictionary, Dict_} -> Dict_;
        undefined -> []
      end,
      RemoteStack = process_info(Stream, current_stacktrace),
      Name = case proplists:get_value(name, Dict, <<"dead stream">>) of
        N when is_binary(N) -> N;
        N when is_atom(N) -> N;
        N -> iolist_to_binary(io_lib:format("~p", [N]))
      end,
      Status = proplists:get_value(status, Dict),
      case Status of
        S when S == starting_transcoder -> ok;
        _ -> events:error("failed to send frame ~p,~p,~p,~p, source_tag=~p
to ~s (~p) in status ~p\n~p\nremote stack:\n~p", [
                         Content, Codec, Flavor, round(DTS),
Frame1#video_frame.source,
                         Name, Stream, Status, Stack, RemoteStack])
      end,
      % [io:format("~10.. s: ~p~n", [K,V]) || {K,V} <- process_info(Stream)]
      {error, timeout}
  end.



this code is helping us for years.  You should remove video specific stuff.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190920/c9685357/attachment.htm>


More information about the erlang-questions mailing list