From: Alan T. DeKok Date: Sat, 3 Apr 2021 12:06:10 +0000 (-0400) Subject: retry on insert failure, due to mutex issues X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=82b8d0f500a8c467282011d571913ad29c123b88;p=thirdparty%2Ffreeradius-server.git retry on insert failure, due to mutex issues --- diff --git a/src/main/listen.c b/src/main/listen.c index 6e28d16616..a94d310226 100644 --- a/src/main/listen.c +++ b/src/main/listen.c @@ -3741,6 +3741,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); @@ -3751,6 +3752,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); @@ -3764,6 +3767,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; } }