Skip to content

Commit

Permalink
Fix invalid call to exit/2 in couch_server
Browse files Browse the repository at this point in the history
Previously we called it as `exit(couch_server_N, config_change)` but exit/2
doesn't know what to do with an atom, it needs a pid.

```
exit(couch_server_1, foo).
** exception error: bad argument
     in function  exit/2
        called as exit(couch_server_1,foo)
        *** argument 1: not a pid
```

This doesn't actually restart the servers as intended and it's also making
quite a mess in the eunit logs.

In addition to ensuring we're calling a Pid, use a `{shutdown, _}` error shape
to avoid triggering verbose SASL report as it's an expected condition.
  • Loading branch information
nickva committed Apr 27, 2024
1 parent 0a431b8 commit f5292d8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/couch/src/couch_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,10 @@ terminate(Reason, Srv) ->
ok.

handle_config_change("couchdb", "database_dir", _, _, N) ->
exit(couch_server(N), config_change),
case whereis(couch_server(N)) of
Pid when is_pid(Pid) -> exit(Pid, {shutdown, config_change});
undefined -> ok
end,
remove_handler;
handle_config_change("couchdb", "update_lru_on_read", "true", _, N) ->
gen_server:call(couch_server(N), {set_update_lru_on_read, true}),
Expand Down Expand Up @@ -719,8 +722,8 @@ handle_cast({close_db_if_idle, DbName}, Server) ->
handle_cast(Msg, Server) ->
{stop, {unknown_cast_message, Msg}, Server}.

handle_info({'EXIT', _Pid, config_change}, Server) ->
{stop, config_change, Server};
handle_info({'EXIT', _Pid, {shutdown, config_change}}, Server) ->
{stop, {shutdown, config_change}, Server};
handle_info({'EXIT', Pid, Reason}, Server) ->
case ets:lookup(couch_dbs_pid_to_name(Server), Pid) of
[{Pid, DbName}] ->
Expand Down

0 comments on commit f5292d8

Please sign in to comment.