Skip to content

Commit

Permalink
Fixes #1107 - Fixed bug identified by kguisti. Infer the max-read-buf…
Browse files Browse the repository at this point in the history
…fers from Proton.
  • Loading branch information
ted-ross committed Jun 5, 2023
1 parent 583bbfa commit 954e3ec
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/adaptors/adaptor_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ int qd_raw_connection_grant_read_buffers(pn_raw_connection_t *pn_raw_conn)
pn_raw_buffer_t raw_buffers[RAW_BUFFER_BATCH];

//
// Get the read-buffer capacity for the connection. Cap this value at the TIER_1 level.
// Get the read-buffer capacity for the connection.
//
size_t capacity = MIN(pn_raw_connection_read_buffers_capacity(pn_raw_conn), TIER_1);
size_t capacity = pn_raw_connection_read_buffers_capacity(pn_raw_conn);

//
// If there's no capacity, exit now before doing any further wasted work.
Expand All @@ -126,6 +126,15 @@ int qd_raw_connection_grant_read_buffers(pn_raw_connection_t *pn_raw_conn)
return 0;
}

//
// 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;
}

//
// Get the "held_by_threads" stats for adaptor buffers as an approximation of how many
// buffers are in-use. This is an approximation since it also counts free buffers held
Expand Down Expand Up @@ -156,7 +165,7 @@ 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.
//
size_t already_granted = TIER_1 - capacity;
size_t already_granted = max_capacity - capacity;

//
// If we desire to grant additional buffers, calculate the number to grant now.
Expand Down

0 comments on commit 954e3ec

Please sign in to comment.