Skip to content
Browse files

Fix issue where the wrong pid was being stored in the list of monitors

When a pid exited while the pool was full and there were blocking
checkouts, poolboy would put the pid of the process requesting a worker
in the monitor tuple along with the monitor ref, instead of the pid of
the worker.
  • Loading branch information...
1 parent ce1cec4 commit 0d9dbeeeba46691b1e54da4f4c7bb1a4720107d5 @Vagabond Vagabond committed
Showing with 13 additions and 7 deletions.
  1. +4 −3 src/poolboy.erl
  2. +5 −2 test/poolboy_eqc.erl
  3. +4 −2 test/poolboy_tests.erl
View
7 src/poolboy.erl
@@ -285,8 +285,9 @@ handle_info({'EXIT', Pid, Reason}, StateName, State) ->
case wait_valid(StartTime, Timeout) of
true ->
MonitorRef = erlang:monitor(process, FromPid),
- Monitors2 = [{FromPid, MonitorRef} | Monitors],
- gen_fsm:reply(From, new_worker(Sup, InitFun)),
+ NewWorker = new_worker(Sup, InitFun),
+ Monitors2 = [{NewWorker, MonitorRef} | Monitors],
+ gen_fsm:reply(From, NewWorker),
{next_state, full, State#state{waiting=LeftWaiting,
monitors=Monitors2}};
_ ->
@@ -305,8 +306,8 @@ handle_info({'EXIT', Pid, Reason}, StateName, State) ->
case wait_valid(StartTime, Timeout) of
true ->
MonitorRef = erlang:monitor(process, FromPid),
- Monitors2 = [{FromPid, MonitorRef} | Monitors],
NewWorker = new_worker(Sup, InitFun),
+ Monitors2 = [{NewWorker, MonitorRef} | Monitors],
gen_fsm:reply(From, NewWorker),
{next_state, full, State#state{waiting=LeftWaiting,
monitors=Monitors2}};
View
7 test/poolboy_eqc.erl
@@ -9,9 +9,12 @@
-include_lib("eunit/include/eunit.hrl").
poolboy_test_() ->
- {timeout, 300,
+ {timeout, 20,
fun() ->
- ?assert(eqc:quickcheck(eqc:testing_time(290, poolboy_eqc:prop_parallel())))
+ ?assert(eqc:quickcheck(eqc:testing_time(4,
+ poolboy_eqc:prop_sequential()))),
+ ?assert(eqc:quickcheck(eqc:testing_time(4,
+ poolboy_eqc:prop_parallel())))
end
}.
View
6 test/poolboy_tests.erl
@@ -245,10 +245,11 @@ worker_death_while_full() ->
Self = self(),
spawn(fun() ->
poolboy:checkout(Pid),
- Self ! got_worker
+ Self ! got_worker,
%% XXX: Don't release the worker. We want to also test what happens
%% when the worker pool is full and a worker dies with no queued
%% checkouts.
+ timer:sleep(5000)
end),
%% Spawned process should block waiting for worker to be available.
@@ -287,9 +288,10 @@ worker_death_while_full_no_overflow() ->
Self = self(),
spawn(fun() ->
poolboy:checkout(Pid),
- Self ! got_worker
+ Self ! got_worker,
%% XXX: Do not release, need to also test when worker dies and no
%% checkouts queued.
+ timer:sleep(5000)
end),
%% Spawned process should block waiting for worker to be available.

0 comments on commit 0d9dbee

Please sign in to comment.
Something went wrong with that request. Please try again.