diff --git a/src/emysql_conn.erl b/src/emysql_conn.erl index 756ad612..66c068a0 100644 --- a/src/emysql_conn.erl +++ b/src/emysql_conn.erl @@ -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.