Allow fast clients to send packets, too
authorAlan T. DeKok <aland@freeradius.org>
Thu, 26 Mar 2009 22:07:17 +0000 (15:07 -0700)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 26 Mar 2009 22:07:17 +0000 (15:07 -0700)
This is for performance testing.  For speed, the server doesn't have
locks all over the place.  However, this means that when it runs threaded,
the client can receive the response, and send a new one using the same
ID, before the child thread has a chance to update child_state.

This work-around lets everyone be happy

src/main/event.c

index 365b4ad..c455f06 100644 (file)
@@ -2685,6 +2685,26 @@ int received_request(rad_listen_t *listener,
                        struct timeval when;
 
                default:
+                       /*
+                        *      Special hacks for race conditions.
+                        *      The reply is encoded, and therefore
+                        *      likely sent.  We received a *new*
+                        *      packet from the client, likely before
+                        *      the next line or two of code which
+                        *      updated the child state.  In this
+                        *      case, just accept the new request.
+                        */
+                       if ((request->reply->code != 0) &&
+                           request->reply->data) {
+                               radlog(L_INFO, "WARNING: Allowing fast client %s port %d - ID: %d for recent request %d.",
+                                      client->shortname,
+                                      packet->src_port, packet->id,
+                                      request->number);
+                               remove_from_request_hash(request);
+                               request = NULL;
+                               break;
+                       }
+
                        gettimeofday(&when, NULL);
                        when.tv_sec -= 1;