Skip to content

Commit

Permalink
Fix the computation of the active_sockets number.
Browse files Browse the repository at this point in the history
If we added a new socket in the recycle_acceptor, we should not decrement the
number of active sockets.
  • Loading branch information
Shayan Pooya committed Mar 24, 2014
1 parent 3138381 commit 1849699
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/mochiweb_socket_server.erl
Expand Up @@ -296,16 +296,16 @@ recycle_acceptor(Pid, State=#mochiweb_socket_server{
State#mochiweb_socket_server{acceptor_pool=Pool1}
end;
false ->
Pool1 =
case sets:size(Pool) < PoolSize of
true ->
Acceptor = mochiweb_acceptor:start_link(self(), Listen, Loop),
sets:add_element(Acceptor, Pool);
false ->
Pool
end,
State#mochiweb_socket_server{active_sockets=ActiveSockets - 1,
acceptor_pool=Pool1}
case sets:size(Pool) < PoolSize of
true ->
Acceptor = mochiweb_acceptor:start_link(self(), Listen, Loop),
Pool1 = sets:add_element(Acceptor, Pool),
State#mochiweb_socket_server{active_sockets=ActiveSockets,
acceptor_pool=Pool1};
false ->
State#mochiweb_socket_server{active_sockets=ActiveSockets - 1,
acceptor_pool=Pool}
end
end.

handle_info(Msg, State) when ?is_old_state(State) ->
Expand Down

3 comments on commit 1849699

@forkbomb-mj
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, is the ActiveSockets forgot to sub 1 in case set:size(Pool) < PoolSize of true?
I find that whenever the number of Acceptor arriving the Max , and then finish all request , the ActiveSockets will increase the number of PoolSize.

@etrepum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the right thing to do at this point is to write some tests that define how it should behave and fix the code if necessary.

@etrepum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please open an issue with any information you have and I'll look into it when I get a chance. If you have the time to write the tests and submit a PR, let me know.

Please sign in to comment.