Permalink
Browse files

Avoid orphaning opened connections during emysql:increment_pool_size/2.

  • Loading branch information...
1 parent 2438031 commit e234672f2f898bdf4daf2131294aab6cf53f238a @csrl csrl committed with Henning Jan 3, 2012
Showing with 9 additions and 1 deletion.
  1. +9 −1 src/emysql_conn.erl
View
@@ -105,7 +105,15 @@ open_n_connections(PoolId, N) ->
%-% io:format("open ~p connections for pool ~p~n", [N, PoolId]),
case emysql_conn_mgr:find_pool(PoolId, emysql_conn_mgr:pools()) of
{Pool, _} ->
- [open_connection(Pool) || _ <- lists:seq(1, N)];
+ lists:foldl(fun(_ ,Connections) ->
+ %% Catch {'EXIT',_} errors so newly opened connections are not orphaned.
+ case catch open_connection(Pool) of
+ #connection{} = Connection ->
+ [Connection | Connections];
+ _ ->
+ Connections
+ end
+ end, [], lists:seq(1, N));
_ ->
exit(pool_not_found)
end.

0 comments on commit e234672

Please sign in to comment.