在 ChicagoBoss mysql 连接自动断爱 提到断开的两种原因
Mysql 模认8小时后自动断开,进程应该监听并能主动再次连接。
花了点时间读了点源码
boss_db:start
|
|-------------> boss_db_sup:start_link <one_for_one>
|
|------------------------>poolboy:start_link <gen_fsm, db_controller>
|
|---------------->poolboy_sup:start_link <simple_one_for_one>
|
|---------->boss_db_controller:start_link
|
|------->boss_db_adapter_mysql
1、首先在boss_db_controller的init中添加process_flag(trap_exit, true),
并添加
172 handle_info(stop, State) ->
173 error_logger:info_msg("~p:handle_info line ~p stop~n", [?MODULE, ?LINE]),
174 {stop, shutdown, State};
175 handle_info({'EXIT', Pid, Why}, State) ->
176 error_logger:info_msg("~p:handle_info line ~p {Pid, Why}=~p~n",
177 [?MODULE, ?LINE, {Pid, Why}]),
178 {stop, shutdown, State};
来主动停止程序,让poolboy_sup重启子进程。
2、其次在boss_db_adapter_mysql.erl
把
22 mysql_conn:start(DBHost, DBPort, DBUsername, DBPassword, DBDatabase,
23 fun(_, _, _, _) -> ok end, Encoding, DBIdentifier).
改为
22 mysql_conn:start_link(DBHost, DBPort, DBUsername, DBPassword, DBDatabase,
23 fun(_, _, _, _) -> ok end, Encoding, DBIdentifier).
修复以上可以解决此问题