Skip to content

Race Condition causes Javascript VMs to never be returned to VM Pool #287

Closed
ian-plosker opened this Issue Feb 15, 2012 · 3 comments

2 participants

@ian-plosker

There is a race condition in the riak_kv_js_manager wherein:

  1. A process (e.g. a pipe fitter) calls riak_kv_js_manager:blocking_dispatch/4
  2. riak_kv_js_manager:blocking_dispatch function calls reserve_vm, a gen_server:call to the riak_kv_js_manager, which reserves a VM
  3. The calling process (e.g. a pipe fitting) is killed before calling riak_kv_js_vm:blocking_dispatch/3, a gen_server:call to the riak_kv_js_manager, which normally would return the JS VM to the VM pool after successfully running the provided JS

In this situation, the reserved JS VM will never be returned to the JS VM pool.

The offending code is as follows:

blocking_dispatch(Name, JSCall, MaxCount, Count) ->
    case reserve_vm(Name) of %% reserve_vm is a gen_server:call to the riak_kv_js_manager
        {ok, VM} ->
            JobId = {VM, make_ref()},
            riak_kv_js_vm:blocking_dispatch(VM, JobId, JSCall); %% riak_kv_js_vm:blocking_dispatch is a gen_server:call to the riak_kv_js_vm
        {error, no_vms} ->
            back_off(MaxCount, Count),
            blocking_dispatch(Name, JSCall, MaxCount, Count - 1)
    end.

The simple solution would appear to be linking the calling process to the JS VM before allowing it to be checkout of the pool.

@rzezeski

Fixed by #294

@rzezeski rzezeski closed this Feb 27, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.