Permalink
Browse files

Cancel waiting when a checkout fails

  • Loading branch information...
1 parent 3899c40 commit 93e38824279f771d3782c4aaf24d85bdbf301c0b @devinus committed Oct 25, 2013
Showing with 11 additions and 1 deletion.
  1. +11 −1 src/poolboy.erl
View
@@ -32,7 +32,13 @@ checkout(Pool, Block) ->
-spec checkout(Pool :: node(), Block :: boolean(), Timeout :: timeout())
-> pid() | full.
checkout(Pool, Block, Timeout) ->
- gen_server:call(Pool, {checkout, Block}, Timeout).
+ try
+ gen_server:call(Pool, {checkout, Block}, Timeout)
+ catch
+ Class:Reason ->
+ gen_server:cast(Pool, {cancel_waiting, self()}),
+ erlang:raise(Class, Reason, erlang:get_stacktrace())
+ end.
-spec checkin(Pool :: node(), Worker :: pid()) -> ok.
checkin(Pool, Worker) when is_pid(Worker) ->
@@ -127,6 +133,10 @@ handle_cast({checkin, Pid}, State = #state{monitors = Monitors}) ->
{noreply, State}
end;
+handle_cast({cancel_waiting, Pid}, State) ->
+ Waiting = queue:filter(fun ({{P, _}, _}) -> P =/= Pid end, State#state.waiting),
+ {noreply, State#state{waiting = Waiting}};
+
handle_cast(_Msg, State) ->
{noreply, State}.

0 comments on commit 93e3882

Please sign in to comment.