anchor.diff:      Pos = rand:uniform(Max),
       ConnId = do_find_conn(Pos, Weights),
       Spec = maps:get(ConnId, ConnSpec),
  -    #conn_spec{id=ConnId, pool=Pool, meta=Meta} = Spec,
  +    #conn_spec{id=ConnId, pool=Pool, max_exclusive=Max, meta=Meta} = Spec,
       ?DEBUG("selected weight ~p: ~p", [Pos, ConnId], State),
       case maps:find(ConnId, ConnStatus) of
           {ok, #conn_status{status=active, conn_pids=Pids}} ->
  -            case length(Pids) < Pool of
  +            ActivePids = length(Pids),
  +            case ActivePids < Pool of
                   true ->
                       % Slots still available
                       connect(Spec, Tries, From, Exclusive, State);
                   false when Exclusive==false ->
                       ?DEBUG("selecting existing pid ~p: ~p", [Pos, ConnId], State),
  -                    gen_server:reply(From, {ok, do_get_pid(Pids), Meta#{conn_id=>ConnId}}),
  +                    Pid = do_get_random_pid(Pids),
  +                    gen_server:reply(From, {ok, Pid, Meta#{conn_id=>ConnId}}),
                       State;
                   false ->
                       % We reached all possible connections
  -                    case do_get_exclusive_pid(Pids, Exclusive, State) of
  -                        {ok, Pid, State2} ->
  -                            ?DEBUG("selecting and locking existing pid ~p: ~p",
  -                                   [Pos, ConnId], State),
  +                    case find_conn_pid_exclusive(Pids, Exclusive, State) of
  +                        {ok, Pid, ConnId, State2} ->
  +                            ?DEBUG("selecting and locking existing pid: ~p", [ConnId], State2),
                               gen_server:reply(From, {ok, Pid, Meta#{conn_id=>ConnId}}),
                               State2;
  -                        false ->
  -                            ?DEBUG("max connections reached", [], State),
  -                            gen_server:reply(From, {error, max_connections_reached}),
  -                            State
  +                        {error, no_free_connections} ->
  +                            case ActivePids < Max of
  +                                true ->
  +                                    connect(Spec, Tries, From, Exclusive, State);
  +                                false ->
  +                                    ?DEBUG("max connections reached", [], State),
  +                                    gen_server:reply(From, {error, max_connections_reached}),
  +                                    State
  +                            end
                       end
               end;
           _ ->
               % If inactive or not yet created
               connect(Spec, Tries, From, Exclusive, State)
  +    end.
  +
  +
  +%% @private
  +find_conn_pid_exclusive(Pids, {true, UserPid}, State) ->
  +    #state{
  +        conn_pids= ConnPids,
  +        conn_user_mons = Mons
  +    } = State,
  +    Pids2 = lists:filter(
  +        fun(Pid) ->
  +            case maps:get(Pid, ConnPids) of
  +                {_ConnId, undefined} -> true;
  +                {_ConnId, _OldRef} -> false
  +            end
  +        end,
  +        Pids),
  +    case Pids2 of
  +        [] ->
  +            {error, no_free_connections};
  +        _ ->
  +            Pid = do_get_random_pid(Pids2),
  +            {ConnId, undefined} = maps:get(Pid, ConnPids),
  +            Mon = monitor(process, UserPid),
  +            State2 = State#state{
  +                conn_pids = ConnPids#{Pid => {ConnId, Mon}},
  +                conn_user_mons = Mons#{Mon => Pid}
  +            },
  +            {ok, Pid, ConnId, State2}
       end.
   
   
  
positive.code:     Specs2 = lists:foldl(
          fun(#nkconn{transp=Transp, ip=Ip, port=Port}=NkConn, Acc) ->
              ConnId = {Transp, Ip, Port},
              ConnSpec = #conn_spec{id=ConnId, nkconn=NkConn, pool=Pool, meta=Meta},
              Acc#{ConnId => ConnSpec}
          end,
          Specs,
  
negative.code: %% in that case one of the connections is selected randomly. If not,
  %% a new connection is started
  %% If we cannot connect to a destination, is marked as failed and retried later
  %% You can also get an exclusive connection, that would be blocked for everyone else
  %% If none is available, new ones will be started (up to max_exclusive)
  %% You must release the connection to be reused, if the process fails it will stop
  %% @see nkpacket_httpc_pool for sample
  
  -module(nkpacket_pool).
  