fix(kafka): fix use-after-free on task cancellation during kafka producer Send#1299
Open
disaykin wants to merge 2 commits into
Open
fix(kafka): fix use-after-free on task cancellation during kafka producer Send#1299disaykin wants to merge 2 commits into
disaykin wants to merge 2 commits into
Conversation
…ucer Send Fixes a Use-After-Free vulnerability in the asynchronous Kafka Producer API when a task is cancelled before librdkafka flushes its queue. The `kafka::Producer::Send` API accepts parameters as views (`string_view`, `zstring_view`, `HeaderViews`). These views point to data owned by the caller. Inside `Send`, raw pointers from these views are passed down to `librdkafka`, which stores them in its internal asynchronous queues for background delivery. If a client connection drops, a cascade cancellation of tasks occurs. This leads to a premature return from `kafka::Producer::Send`, causing the caller to destroy the original payload memory. However, `librdkafka` still retains these pointers and attempts to access them during subsequent network flushes to the broker, resulting in memory corruption. To fix this, we ensure that `Producer::Send` is blocked from returning prematurely and cannot exit until the background `SendImpl` completes its interaction with `librdkafka`. Co-authored-by: Aleksander Rypalov <rypalov2002@gmail.com>
disaykin
force-pushed
the
kafka-producer-cancellation-fix
branch
from
July 17, 2026 09:01
30e88de to
82e223b
Compare
Old URL returns 404 now
Contributor
Author
|
@apolukhin прошу ревью. проблему с установкой кафки в тестах я починил (там протух урл), но вот что делать с флапающим тестом на постгрю - не знаю: Но это точно не относится к моему фиксу. Также проблема компиляции с rabbitmq на debian12 привнесена не мной/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a Use-After-Free vulnerability in the asynchronous Kafka Producer API when a task is cancelled before librdkafka flushes its queue.
The
kafka::Producer::SendAPI accepts parameters as views (string_view,zstring_view,HeaderViews). These views point to data owned by the caller. InsideSend, raw pointers from these views are passed down tolibrdkafka, which stores them in its internal asynchronous queues for background delivery.If a client connection drops, a cascade cancellation of tasks occurs. This leads to a premature return from
kafka::Producer::Send, causing the caller to destroy the original payload memory. However,librdkafkastill retains these pointers and attempts to access them during subsequent network flushes to the broker, resulting in memory corruption.To fix this, we ensure that
Producer::Sendis blocked from returning prematurely and cannot exit until the backgroundSendImplcompletes its interaction withlibrdkafka.Note: by creating a PR or an issue you automatically agree to the CLA. See CONTRIBUTING.md. Feel free to remove this note, the agreement holds.