Skip to content

Commit

Permalink
mc_cursor finishes returning before stopping
Browse files Browse the repository at this point in the history
Prior to this, `mc_cursor` processes would shut down after returning the last result, rather than after
returning a final 'empty' to callers. This caused callers to try to call back for 'next()' again when
cursor was already down or going down. That call is a `gen_server:call()`. In the best case, the process
would already be down, and the call would result in a `noproc` exit, which this code catches and
translates into a return value of 'error', instead of the correct `{}` value. In rare cases, though,
due to `gen_server` code, the call would occur at the moment the process terminates, and you'll get
an `exit(normal)` on the calling process instead.
  • Loading branch information
samwar authored Nov 16, 2021
1 parent f4aadd9 commit b90dee0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/connection/mc_cursor.erl
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,22 @@ init([Owner, Connection, Collection, Cursor, BatchSize, Batch]) ->
%% @hidden
handle_call({next, Timeout}, _From, State) ->
case next_i(State, Timeout) of
{Reply, #state{cursor = 0, batch = []} = UpdatedState} ->
{stop, normal, Reply, UpdatedState};
{{}, UpdatedState} ->
{stop, normal, {}, UpdatedState};
{Reply, UpdatedState} ->
{reply, Reply, UpdatedState}
end;
handle_call({rest, Limit, Timeout}, _From, State) ->
case rest_i(State, Limit, Timeout) of
{Reply, #state{cursor = 0} = UpdatedState} ->
{stop, normal, Reply, UpdatedState};
{{}, UpdatedState} ->
{stop, normal, {}, UpdatedState};
{Reply, UpdatedState} ->
{reply, Reply, UpdatedState}
end;
handle_call({next_batch, Timeout}, _From, State = #state{batchsize = Limit}) ->
case rest_i(State, Limit, Timeout) of
{Reply, #state{cursor = 0} = UpdatedState} ->
{stop, normal, Reply, UpdatedState};
{{}, UpdatedState} ->
{stop, normal, {}, UpdatedState};
{Reply, UpdatedState} ->
{reply, Reply, UpdatedState}
end.
Expand Down

0 comments on commit b90dee0

Please sign in to comment.