Request queue issue with riakc_pb_socket

Bryan Fink bryan at
Thu Aug 2 13:02:24 EDT 2012

On Tue, Jul 24, 2012 at 8:48 PM, Julian <jpellico at> wrote:
> I'm using riakc_pb_socket to queue up several requests and rely on the
> built-in queueing, which should hopefully eventually service all requests.
> However I have a scenario in which a couple processes that queue a request
> are never terminating the call on the socket...even though a request issued
> subsequently gets through.

Hi, Julian. I have one possible answer for you. Could you please try
wrapping your call to riakc_pb_socket:search/5 in a try-catch block?

Deep inside riakc_pb_socket, that call becomes a gen_server:call to
the socket server. If that call times out (or encounters a few other
errors), the calling process (your code) exits with an exception. A
timeout here should be a rare occurrence, because the socket server
should be normally be unblocked, ready to handle (enqueue) requests,
but it's possible, and there are other errors that can trigger the
same behavior.

So, try setting things up as:

    populate_instance(InstanceBin, State) ->
        error_logger:info_msg(binary_to_list(InstanceBin) ++ " about to wait"),
        try riakc_pb_socket:search(...) of
            {ok, MapredResult} ->
                error_logger:info_msg(binary_to_list(InstanceBin) ++ "
done waiting"),
                ...process MapredResult...;
            {error, _} ->
                error_logger:info_msg(binary_to_list(InstanceBin) ++ "
encountered error")
        catch exit:_ ->
            error_logger:info_msg(binary_to_list(InstanceBin) ++ "
failed call, retrying..."),
            populate_instance(InstanceBin, State)

(obviously needs some safety valves to prevent infinite retries, etc.,
but you get the idea)

I consider this a little bit of a long shot, since your timeout is so
long, but it's the only way I've been able to recreate such a
situation so far.


More information about the riak-users mailing list