Skip to content

Commit

Permalink
Fixes skupperproject#1198: make raw connection max capacity updates a…
Browse files Browse the repository at this point in the history
…tomic
  • Loading branch information
kgiusti committed Sep 20, 2023
1 parent eb6e1fa commit f249c0a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
15 changes: 9 additions & 6 deletions src/adaptors/adaptor_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include <inttypes.h>
#include <sys/socket.h>
#include <stdatomic.h>

ALLOC_DEFINE(qd_adaptor_config_t);

Expand Down Expand Up @@ -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 expected = atomic_load(&max_capacity);
while (capacity > expected) {
if (atomic_compare_exchange_weak(&max_capacity, &expected, capacity))
break;
}

//
Expand All @@ -173,9 +176,9 @@ 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;
size_t already_granted = atomic_load(&max_capacity) - capacity;

//
// If we desire to grant additional buffers, calculate the number to grant now.
Expand Down
12 changes: 8 additions & 4 deletions src/adaptors/tcp_lite/tcp_lite.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

#include "tcp_lite.h"

#include <stdatomic.h>

//
// Function suffixes in this module:
//
Expand Down Expand Up @@ -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 expected = atomic_load(&max_capacity);
while (capacity > expected) {
if (atomic_compare_exchange_weak(&max_capacity, &expected, capacity))
break;
}

//
Expand All @@ -539,7 +543,7 @@ 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;
size_t already_granted = atomic_load(&max_capacity) - capacity;

//
// If we desire to grant additional buffers, calculate the number to grant now.
Expand Down
6 changes: 0 additions & 6 deletions tests/tsan.supp
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down

0 comments on commit f249c0a

Please sign in to comment.