]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
retry on insert failure, due to mutex issues
authorAlan T. DeKok <aland@freeradius.org>
Sat, 3 Apr 2021 12:06:10 +0000 (08:06 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 22 Jul 2021 13:55:23 +0000 (09:55 -0400)
src/main/listen.c

index 6050142cf2b4b4c617f454033402546da40c3331..6dbac3b7919e066ea59c4becb590039a8f1d8299 100644 (file)
@@ -3778,6 +3778,7 @@ void listen_coa_free(void)
  */
 void listen_coa_add(rad_listen_t *this, char const *key)
 {
+       int trues = 0;
        coa_key_t my_key, *coa_key;
 
        rad_assert(this->send_coa);
@@ -3788,6 +3789,8 @@ void listen_coa_add(rad_listen_t *this, char const *key)
         *      Find the key.  If we can't find it, then create it.
         */
        memcpy(&my_key.key, &key, sizeof(key)); /* const issues */
+
+retry:
        coa_key = rbtree_finddata(coa_tree, &my_key);
        if (!coa_key) {
                coa_key = talloc_zero(NULL, coa_key_t);
@@ -3801,6 +3804,16 @@ void listen_coa_add(rad_listen_t *this, char const *key)
 
                if (!rbtree_insert(coa_tree, coa_key)) {
                        talloc_free(coa_key);
+
+                       /*
+                        *      The lookups are mutex protected, but
+                        *      if there's time between the lookup and
+                        *      the insert, another thread may have
+                        *      created the node.  In which case we
+                        *      try again.
+                        */
+                       if (tries < 3) goto retry;
+                       tries++;
                        return;
                }
        }