Github user kxepal commented on a diff in the pull request:
https://github.com/apache/couchdb-couch-replicator/pull/6#discussion_r22749730
--- Diff: src/couch_replicator.erl ---
@@ -210,26 +214,41 @@ cancel_replication(RepId, #user_ctx{name = Name,
roles = Roles}) ->
true ->
cancel_replication(RepId);
false ->
- {BaseId, Ext} = RepId,
- case lists:keysearch(
- BaseId ++ Ext, 1,
supervisor:which_children(couch_replicator_job_sup)) of
- {value, {_, Pid, _, _}} when is_pid(Pid) ->
- case (catch gen_server:call(Pid, get_details, infinity)) of
+ case find_replicator(RepId) of
+ {ok, Pid} ->
+ case details(Pid) of
{ok, #rep{user_ctx = #user_ctx{name = Name}}} ->
cancel_replication(RepId);
{ok, _} ->
throw({unauthorized,
<<"Can't cancel a replication triggered by another
user">>});
- {'EXIT', {noproc, {gen_server, call, _}}} ->
- {error, not_found};
Error ->
- throw(Error)
+ Error
end;
- _ ->
- {error, not_found}
+ Error ->
+ Error
end
end.
+find_replicator({BaseId, Ext} = _RepId) ->
+ case lists:keysearch(
+ BaseId ++ Ext, 1,
supervisor:which_children(couch_replicator_job_sup)) of
+ {value, {_, Pid, _, _}} when is_pid(Pid) ->
+ {ok, Pid};
+ _ ->
+ {error, not_found}
+ end.
+
+details(Pid) ->
+ case (catch gen_server:call(Pid, get_details, infinity)) of
--- End diff --
`gen_server:call` with infinity is not a good practice. Timeouts should
always be limited by some sane value we want to wait for, otherwise we'll hang
here forever.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---