extend/ranch — pull request #28 by fishcakez (2013-01-23 01:22:23+00:00)
Title: Setting max connections from integer to infinity causes listener to crash soon after

Currently once max connections has been relaxed to infinity (from an integer) the listener will still receive 'DOWN' messages. As rm_diff has been set to 0, the first one of these will causes the listener to call ranch_server:remove_connection(self()). However the ets object no longer exists, so the listener fails with badarg.

As the count is effectively 0, and this is the value returned by listener:remove_connection, the rm_diff should be the total number of active monitors. This is current rm_diff + current connection count. Therefore a 'DOWN' message should never trigger a ranch_server:remove_connection/2 on the listener because once rm_diff = 0 there are no more monitors.

This patch has the added bonus of preventing a potential negative count if the max connection limit is set back to an integer, which is currently possible (if the listener did not crash).