diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2014-08-21 17:51:07 +0100 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2014-08-21 17:51:07 +0100 |
commit | 760d6145334610e60c76554f92deb9a14319481b (patch) | |
tree | e98a7138af433eaa6295ce0aed09cf581fc15ac8 /src/worker_pool.erl | |
parent | bee74c93b7274e424abb90dea1e50018e06bba9b (diff) | |
download | rabbitmq-server-760d6145334610e60c76554f92deb9a14319481b.tar.gz |
Make Mnesia tx worker pool jobs use a disposable process so that if mnesia_locker decides to randomly send a message there later it will just get dropped and not cause chaos.
Diffstat (limited to 'src/worker_pool.erl')
-rw-r--r-- | src/worker_pool.erl | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/worker_pool.erl b/src/worker_pool.erl index b1dba5a2..2646258d 100644 --- a/src/worker_pool.erl +++ b/src/worker_pool.erl @@ -28,7 +28,8 @@ -behaviour(gen_server2). --export([start_link/0, submit/1, submit_async/1, ready/1, idle/1]). +-export([start_link/0, submit/1, submit/2, submit_async/1, ready/1, + idle/1]). -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). @@ -41,6 +42,7 @@ -spec(start_link/0 :: () -> {'ok', pid()} | {'error', any()}). -spec(submit/1 :: (fun (() -> A) | mfargs()) -> A). +-spec(submit/2 :: (fun (() -> A) | mfargs(), boolean()) -> A). -spec(submit_async/1 :: (fun (() -> any()) | mfargs()) -> 'ok'). -spec(ready/1 :: (pid()) -> 'ok'). -spec(idle/1 :: (pid()) -> 'ok'). @@ -61,10 +63,14 @@ start_link() -> gen_server2:start_link({local, ?SERVER}, ?MODULE, [], [{timeout, infinity}]). submit(Fun) -> + submit(Fun, false). + +%% OneOffProcess =:= true is for working around the mnesia_locker bug. +submit(Fun, OneOffProcess) -> case get(worker_pool_worker) of true -> worker_pool_worker:run(Fun); _ -> Pid = gen_server2:call(?SERVER, {next_free, self()}, infinity), - worker_pool_worker:submit(Pid, Fun) + worker_pool_worker:submit(Pid, Fun, OneOffProcess) end. submit_async(Fun) -> gen_server2:cast(?SERVER, {run_async, Fun}). |