]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Correct logic in reconnect
authorAlan T. DeKok <aland@freeradius.org>
Sun, 16 Oct 2011 02:21:32 +0000 (04:21 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 17 Oct 2011 14:45:00 +0000 (16:45 +0200)
Only complain once per second.

Return correct handle

src/main/connection.c

index f6d36870928f1d8433829a7f8f9f21ac7a78da16..0fd8befbcfa167d4bff052051eff091df7d33fb1 100644 (file)
@@ -58,6 +58,7 @@ struct fr_connection_pool_t {
 
        time_t          last_checked;
        time_t          last_spawned;
+       time_t          last_complained;
 
        int             max_uses;
        int             lifetime;
@@ -545,37 +546,43 @@ void *fr_connection_reconnect(fr_connection_pool_t *fc, void *conn)
         *      order to find top of the parent structure.
         */
        for (this = fc->head; this != NULL; this = this->next) {
-               if (this->connection == conn) {
-                       rad_assert(this->used == TRUE);
+               if (this->connection != conn) continue;
+
+               rad_assert(this->used == TRUE);
                        
-                       DEBUG("%s: Reconnecting (%i)", fc->log_prefix, conn_number);
+               DEBUG("%s: Reconnecting (%i)", fc->log_prefix, conn_number);
                        
-                       new_conn = fc->create(fc->ctx);
-                       if (!new_conn) {
-                               fr_connection_close(fc, conn);
-                               pthread_mutex_unlock(&fc->mutex);
-
-                               /*
-                                *      Can't create a new socket.
-                                *      Try grabbing a pre-existing one.
-                                */
-                               this = fr_connection_get(fc);
-                               if (!new_conn) {
-                                       radlog(L_ERR, "%s: Failed to reconnect (%i), and no other connections available",
-                                              fc->log_prefix, conn_number);
-                               } else {
-                                       DEBUG("%s: Failed to reconnect (%i), using connection (%i)",
-                                             fc->log_prefix, conn_number, this->number);
-                               }
-                               
-                               return this;
+               new_conn = fc->create(fc->ctx);
+               if (!new_conn) {
+                       time_t now = time(NULL);
+
+                       if (fc->last_complained == now) {
+                               now = 0;
+                       } else {
+                               fc->last_complained = now;
                        }
 
-                       fc->delete(fc->ctx, conn);
-                       this->connection = new_conn;
+                       fr_connection_close(fc, conn);
                        pthread_mutex_unlock(&fc->mutex);
-                       return new_conn;
+
+                       /*
+                        *      Can't create a new socket.
+                        *      Try grabbing a pre-existing one.
+                        */
+                       new_conn = fr_connection_get(fc);
+                       if (new_conn) return new_conn;
+
+                       if (!now) return NULL;
+
+                       radlog(L_ERR, "%s: Failed to reconnect (%i), and no other connections available",
+                              fc->log_prefix, conn_number);
+                       return NULL;
                }
+
+               fc->delete(fc->ctx, conn);
+               this->connection = new_conn;
+               pthread_mutex_unlock(&fc->mutex);
+               return new_conn;
        }
 
        pthread_mutex_unlock(&fc->mutex);