diff --git a/src/adaptors/adaptor_common.c b/src/adaptors/adaptor_common.c index 69438bbbb..9510b9251 100644 --- a/src/adaptors/adaptor_common.c +++ b/src/adaptors/adaptor_common.c @@ -31,6 +31,7 @@ #include #include +#include ALLOC_DEFINE(qd_adaptor_config_t); @@ -143,11 +144,13 @@ int qd_raw_connection_grant_read_buffers(pn_raw_connection_t *pn_raw_conn) // // Since we can't query Proton for the maximum read-buffer capacity, we will infer it from - // calls to pn_raw_connection_read_buffers_capacity. + // calls to pn_raw_connection_read_buffers_capacity and track the largest value returned. // - static size_t max_capacity = 0; - if (capacity > max_capacity) { - max_capacity = capacity; + static atomic_size_t max_capacity; // global + size_t current_mc = atomic_load(&max_capacity); + while (capacity > current_mc) { + if (atomic_compare_exchange_weak(&max_capacity, ¤t_mc, capacity)) + break; } // @@ -173,9 +176,11 @@ int qd_raw_connection_grant_read_buffers(pn_raw_connection_t *pn_raw_conn) // // Determine how many of the desired buffers are already granted. This will always be a - // non-negative value. + // non-negative value since max_capacity will always be >= capacity // - size_t already_granted = max_capacity - capacity; + current_mc = atomic_load(&max_capacity); + assert(current_mc >= capacity); + size_t already_granted = current_mc - capacity; // // If we desire to grant additional buffers, calculate the number to grant now. diff --git a/src/adaptors/tcp_lite/tcp_lite.c b/src/adaptors/tcp_lite/tcp_lite.c index c33bf3193..9c1d39bd1 100644 --- a/src/adaptors/tcp_lite/tcp_lite.c +++ b/src/adaptors/tcp_lite/tcp_lite.c @@ -33,6 +33,8 @@ #include "tcp_lite.h" +#include + // // Function suffixes in this module: // @@ -510,9 +512,11 @@ static void grant_read_buffers_XSIDE_IO(tcplite_connection_t *conn, const size_t // Since we can't query Proton for the maximum read-buffer capacity, we will infer it from // calls to pn_raw_connection_read_buffers_capacity. // - static size_t max_capacity = 0; - if (capacity > max_capacity) { - max_capacity = capacity; + static atomic_size_t max_capacity; + size_t current_mc = atomic_load(&max_capacity); + while (capacity > current_mc) { + if (atomic_compare_exchange_weak(&max_capacity, ¤t_mc, capacity)) + break; } // @@ -539,7 +543,9 @@ static void grant_read_buffers_XSIDE_IO(tcplite_connection_t *conn, const size_t // // Determine how many buffers are already granted. This will always be a non-negative value. // - size_t already_granted = max_capacity - capacity; + current_mc = atomic_load(&max_capacity); + assert(current_mc >= capacity); + size_t already_granted = current_mc - capacity; // // If we desire to grant additional buffers, calculate the number to grant now. diff --git a/tests/tsan.supp b/tests/tsan.supp index b43ba6fb5..9e640c5f3 100644 --- a/tests/tsan.supp +++ b/tests/tsan.supp @@ -76,12 +76,6 @@ race:^__lws_logv$ # ISSUE-537 - Suppress the race in qd_entity_refresh_connector for now. race:^qd_entity_refresh_connector$ -# ISSUE-1198: Suppress warnings on race in updating max_capacity -# https://github.com/skupperproject/skupper-router/issues/1198 -race:^qd_raw_connection_grant_read_buffers$ -race:^grant_read_buffers_XSIDE_IO$ - - # # External libraries #