Error when stopping / restarting sender
Our application can create, start, and stop multiple simultaneous RIST queues. We occasionally encounter the "Sender queue is full ..." error when restarting a queue. This error, based on the logic in rist_sender_enqueue, indicates that sender_delete_index + sender_queue_size > sender_write_index.
(Note: If sender_write_index is 0, sender_delete_index + buffer_size cannot be less than sender_write_index...)
The issue appears to be related to the value of the static local variable buffer_size in sender_send_data(...). Within this function, sender_queue_delete_index is set as "sender_queue_read_index - buffer_size". When a new queue is created, buffer_size can hold a positive value, causing sender_queue_delete_index to be set to a value near the maximum of 524,288, while sender_queue_size is close to 0.
I've attempted two different fixes, both of which seem to work, but I'm unsure which is the best approach:
-
Using a non-static buffer_size in the RIST context and initializing it to 0 when the queue is created. This is the most direct fix as it ensures every "start" operation begins from an identical state. However, I'm concerned that this situation might still occur during a buffer wrap-around.
-
Modifying the check in rist_sender_enqueue.
The original condition is:
sender_write_index > 0 and sender_delete_plus_buffer_index > sender_write_index
This would be changed to something like:
(sender_delete_plus_buffer_index - sender_write_index - 1) & (ctx to sender_queue_max - 1) < ctx to sender_queue_max/2
This modification involves computing the distance between the indices and comparing the result to half the buffer size to determine if the distance is "positive" or "negative" in the circular buffer context.
Thanks