Skip to content
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
18 changes: 18 additions & 0 deletions kafka/src/kafka/producer.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include <userver/kafka/producer.hpp>

#include <userver/engine/task/cancel.hpp>
#include <userver/formats/json/value_builder.hpp>
#include <userver/formats/serialize/common_containers.hpp>
#include <userver/kafka/impl/configuration.hpp>
#include <userver/kafka/impl/stats.hpp>
#include <userver/logging/log.hpp>
#include <userver/testsuite/testpoint.hpp>
#include <userver/tracing/span.hpp>
#include <userver/utils/async.hpp>
Expand Down Expand Up @@ -136,6 +138,14 @@ void Producer::Send(
std::optional<std::uint32_t> partition,
HeaderViews headers
) const {
engine::TaskCancellationBlocker blocker;

if (engine::current_task::IsCancelRequested())

@ArkadyRudenko ArkadyRudenko Jul 22, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавь тест, в котором таска отменяется и происходит use-after-free. Чтобы хотя бы локально убедиться, что бага есть, а после фикса её нет

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это будет флаки тест. Даже при наличии бага, он будет фейлиться не каждый раз. И фэйлиться будет только под адрес-санитайзером. Я пробовал написать, получается как-то не очень... Попробую откопать свои наработки, может очередная попытка родит что-то удачнее

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

О, придумал. Можно выставить большие значения либрдкафка накопления очереди перед сбросом (1000 сообщений, 1 секунда, что раньше наступит). Тогда тест будет не флаки под санитайзером

@ArkadyRudenko ArkadyRudenko Jul 22, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вообще,я имел ввиду, чтобы ты показал нам тест и локально убедился, что он падает без твоего фикса. А с фиксом чинится (и потом его удалить и не мержить). Но если получится даже полноцнный сделать, то шикарно

{
LOG_WARNING("Task cancellation requested. Skip sending message");
return;
}

utils::Async(producer_task_processor_, "producer_send", [this, topic_name, key, message, partition, &headers] {
SendImpl(topic_name, key, message, partition, impl::HeadersHolder{headers});
}).Get();
Expand All @@ -148,6 +158,14 @@ void Producer::SendWrapper(
std::optional<std::uint32_t> partition,
HeaderViews headers
) const {
engine::TaskCancellationBlocker blocker;

if (engine::current_task::IsCancelRequested())
{
LOG_WARNING("Task cancellation requested. Skip sending messages");
return;
}

utils::Async(
producer_task_processor_,
"producer_send_bulk",
Expand Down
7 changes: 3 additions & 4 deletions scripts/kafka/ubuntu_install_kafka.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
# Exit on any error and treat unset variables as errors, print all commands
set -o errexit -o nounset -o pipefail -o posix -x

KAFKA_VERSION=4.0.1
KAFKA_VERSION=4.3.1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you increas it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Старая ссылка для установки кафки больше не работает. Заменил на ссылку для скачивания с их официального сайта

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Предлагаете оформить это отдельным запросом на влитие? Или претензия именно к изменению версии? Старая версия у меня вроде бы не захотела скачиваться по новой ссылке...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если у них на сайте теперь написано, что надо так, то окей

KAFKA_HOME=/etc/kafka
KAFKA_URL="https://www.apache.org/dyn/closer.lua/kafka/${KAFKA_VERSION}/kafka_2.13-${KAFKA_VERSION}.tgz?action=download"

DEBIAN_FRONTEND=noninteractive sudo apt install -y openjdk-17-jdk

curl "https://dlcdn.apache.org/kafka/$KAFKA_VERSION/kafka_2.13-$KAFKA_VERSION.tgz" -o kafka.tgz
mkdir -p "$KAFKA_HOME"
tar -xzf kafka.tgz --directory="$KAFKA_HOME" --strip-components=1
rm kafka.tgz
curl -fsSL "$KAFKA_URL" | tar -xzf - --directory="$KAFKA_HOME" --strip-components=1
Loading