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-Tag: release_3_0_24~138 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fe28486a2dc55c6df83d88c15887c110eca0d2c7;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 6050142cf2b..6dbac3b7919 100644 --- a/src/main/listen.c +++ b/src/main/listen.c @@ -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; } }