Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix data race when a buffer queue is being reset instead of being initialized #4718

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# librdkafka v2.4.º

librdkafka v2.4.1 is a maintenance release:

* Fix data race when buffer queues are being reset instead of being
initialized (#4718)


## Fixes

### General fixes

* Issues: #4522.
A data race happened when emptying buffers of a failing broker, in its thread,
with the statistics callback in main thread gathering the buffer counts.
Solved by resetting the atomic counters instead of initializing them.
Happening since 1.x (#4718).



# librdkafka v2.4.0

librdkafka v2.4.0 is a feature release:
Expand Down
8 changes: 7 additions & 1 deletion src/rdkafka_buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ void rd_kafka_bufq_init(rd_kafka_bufq_t *rkbufq) {
rd_atomic32_init(&rkbufq->rkbq_msg_cnt, 0);
}

static void rd_kafka_bufq_reset(rd_kafka_bufq_t *rkbufq) {
TAILQ_INIT(&rkbufq->rkbq_bufs);
rd_atomic32_set(&rkbufq->rkbq_cnt, 0);
rd_atomic32_set(&rkbufq->rkbq_msg_cnt, 0);
}

/**
* Concat all buffers from 'src' to tail of 'dst'
*/
Expand All @@ -252,7 +258,7 @@ void rd_kafka_bufq_concat(rd_kafka_bufq_t *dst, rd_kafka_bufq_t *src) {
(void)rd_atomic32_add(&dst->rkbq_cnt, rd_atomic32_get(&src->rkbq_cnt));
(void)rd_atomic32_add(&dst->rkbq_msg_cnt,
rd_atomic32_get(&src->rkbq_msg_cnt));
rd_kafka_bufq_init(src);
rd_kafka_bufq_reset(src);
}

/**
Expand Down