来自已终止进程的错误报告(预期是正常的)

Error Report from a terminated process (expected to be normal)

我有一个测试模块可以测试我的 Table 模块。 我的 Table 模块在终止时调用:

terminate(_, State = {Board, Status, Players}) ->
  gen_server:stop(Board),
  ...stopping other processes,
  io:format("Table Terminating.~p~n", [State]),
  ok.

这是我的代码中唯一会停止 Board 进程的部分。

在 运行 我的测试之后,我将在大约一分钟后得到这个:

=ERROR REPORT==== 21-Jul-2017::22:28:40 ===
** Generic server <0.92.0> terminating
** Last message in was []
** When Server state == [[{spawn,x,none},
                          {recent,x,none},
                          {empty,null,none},
                          {empty,null,none},
                          {empty,null,none}],
                         [{empty,null,none},
                          {empty,null,none},
                          {empty,null,none},
                          {ridge,null,none},
                          {empty,null,none}],
                         [{empty,null,none},
                          {empty,null,none},
                          {ridge,null,none},
                          {empty,null,none},
                          {empty,null,none}],
                         [{empty,null,none},
                          {ridge,null,none},
                          {empty,null,none},
                          {empty,null,none},
                          {empty,null,none}],
                         [{empty,null,none},
                          {empty,null,none},
                          {empty,null,none},
                          {empty,null,none},
                          {spawn,o,none}]]
** Reason for termination ==
** {terminated,[{io,format,
                    [<0.90.0>,"Board.~p~n",
                     [[[{spawn,x,none},
                        {recent,x,none},
                        {empty,null,none},
                        {empty,null,none},
                        {empty,null,none}],
                       [{empty,null,none},
                        {empty,null,none},
                        {empty,null,none},
                        {ridge,null,none},
                        {empty,null,none}],
                       [{empty,null,none},
                        {empty,null,none},
                        {ridge,null,none},
                        {empty,null,none},
                        {empty,null,none}],
                       [{empty,null,none},
                        {ridge,null,none},
                        {empty,null,none},
                        {empty,null,none},
                        {empty,null,none}],
                       [{empty,null,none},
                        {empty,null,none},
                        {empty,null,none},
                        {empty,null,none},
                        {spawn,o,none}]]]],
                    []},
                {board,terminate,2,[{file,"board.erl"},{line,319}]},
                {gen_server,try_terminate,3,
                            [{file,"gen_server.erl"},{line,629}]},
                {gen_server,terminate,7,[{file,"gen_server.erl"},{line,795}]},
                {proc_lib,init_p_do_apply,3,
                          [{file,"proc_lib.erl"},{line,247}]}]

看起来 Board 模块未正确终止。 Board的结尾是这样的:

terminate(normal, State) ->
    io:format("Board.~p~n", [State]),
    ok.

我试图在独立模块中重现它,b:

-module(b).
-compile(export_all).

init([]) -> {ok, {1, 2}}.

terminate(_, State) ->
  io:format("Table Terminating.~p~n", [State]),
  ok.

code_change(_OldVsn, State, _Extra) ->
    {ok, State}. 

handle_cast(_, State) ->
    {noreply, State}.

handle_info(Msg, State) ->
  io:format("Unexpected message: ~p~n",[Msg]),
  {noreply, State}.

go() ->
  gen_server:start_link(?MODULE, [], []).

未成功:

4> {ok, B} = b:go(). {ok,<0.74.0>} 5> gen_server:stop(B). Table Terminating.{1,2}

我想知道的是,我应该寻找什么样的代码才能使我的董事会得到 ** Reason for termination == ** {terminated 停止的理由?

完整的源代码在这里:git@github.com:QuantumProductions/tunnel.git

编辑:董事会包括这个

handle_call(stop, _From, State) ->
    {stop, normal, shutdown_ok, State};
handle_call(_, _, Board) ->
  {reply, {error, unrecognized, Board}, Board}.

编辑:我最好的猜测是 eunit 是在其测试中创建的自动终止进程吗?

为什么 borad 最后一条消息是 []?根据您使用的代码,gen_server:stop/1 调用 gen:stop/1,调用 gen:stop/3,调用 proc_lib:stop/3 which finally calls sys:terminate/3. When you call sys:terminate/3 for a gen_server, sys calls gen_server:system_terminate/4 and it calls gen_server:terminate/6,最后一条消息是 []

为什么 borad{terminated, ...} 原因终止?根据io代码,io:format/2最后调用io:execute_request/2 and you got this because io process terminated and in here就变成了{terminated, ...}.