Attached is an improved version of one of the patches originally posted here.

http://lists.freeradius.org/pipermail/freeradius-users/2012-May/060820.html

It moves decrements of socket/client num_connections counters into event_new_fd 
so that it
happens on all paths by which a connection may be removed.  As the code now 
stands,
when a connection is terminated by the other side, num_connections continues to 
count
it towards connection limits.

(Note that with the above code, num_connections will still count a dead 
connection
towards limits until it has been abandoned by all users and cleaned up.  Also 
I'm not completely
sure this is immune to races since I haven't yet figured out if the connection 
garbage collection
might be reentrant.)

This has been tested in a radsec pure-proxy relay setup.  It has not yet been 
tested in an AS
setup.

diff --git a/src/main/listen.c b/src/main/listen.c
index cb774d5..e39ee4f 100644
--- a/src/main/listen.c
+++ b/src/main/listen.c
@@ -476,14 +476,4 @@ static int dual_tcp_recv(rad_listen_t *listener)
 
 		/*
-		 *	Decrement the number of connections.
-		 */
-		if (sock->parent->limit.num_connections > 0) {
-			sock->parent->limit.num_connections--;
-		}
-		if (sock->client->limit.num_connections > 0) {
-			sock->client->limit.num_connections--;
-		}
-
-		/*
 		 *	Tell the event handler that an FD has disappeared.
 		 */
diff --git a/src/main/process.c b/src/main/process.c
index bc1b35e..6b369d8 100644
--- a/src/main/process.c
+++ b/src/main/process.c
@@ -1603,5 +1603,5 @@ static void remove_from_proxy_hash_nl(REQUEST *request)
 
 	/*
-	 *	Got from YES in hash, to NO, not in hash while we hold
+	 *	Go from YES in hash, to NO, not in hash while we hold
 	 *	the mutex.  This guarantees that when another thread
 	 *	grabs the mutex, the "not in hash" flag is correct.
@@ -3770,4 +3770,13 @@ finish:
 #endif
 
+		if (sock->parent) {
+			if (sock->parent->limit.num_connections > 0) {
+				sock->parent->limit.num_connections--;
+			}
+			if (sock->client->limit.num_connections > 0) {
+				sock->client->limit.num_connections--;
+			}
+		}
+
 		/*
 		 *	Remove any pending cleanups.
diff --git a/src/main/tls_listen.c b/src/main/tls_listen.c
index 91eeec8..d7edacd 100644
--- a/src/main/tls_listen.c
+++ b/src/main/tls_listen.c
@@ -77,16 +77,4 @@ static void tls_socket_close(rad_listen_t *listener)
 	listener->tls = NULL; /* parent owns this! */
 	
-	if (sock->parent) {
-		/*
-		 *	Decrement the number of connections.
-		 */
-		if (sock->parent->limit.num_connections > 0) {
-			sock->parent->limit.num_connections--;
-		}
-		if (sock->client->limit.num_connections > 0) {
-			sock->client->limit.num_connections--;
-		}
-	}
-	
 	/*
 	 *	Tell the event handler that an FD has disappeared.
-
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html

Reply via email to