From 3458d16361b7da64919d63ede7efeafd8d7334ae Mon Sep 17 00:00:00 2001 From: Dan Jaglowski Date: Thu, 26 Sep 2024 11:22:22 -0400 Subject: [PATCH] [receiver/kafka] Use proper context for shutdown --- .chloggen/kafka-receiver-context-fix.yaml | 27 +++++++++++++++++++++++ receiver/kafkareceiver/kafka_receiver.go | 5 ++--- 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 .chloggen/kafka-receiver-context-fix.yaml diff --git a/.chloggen/kafka-receiver-context-fix.yaml b/.chloggen/kafka-receiver-context-fix.yaml new file mode 100644 index 000000000000..36b2839c6846 --- /dev/null +++ b/.chloggen/kafka-receiver-context-fix.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: 'bug_fix' + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: receiver/kafka + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Fix issue where shutdown could hang indefinitely. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [30789] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] diff --git a/receiver/kafkareceiver/kafka_receiver.go b/receiver/kafkareceiver/kafka_receiver.go index 750955366816..b476f2e215cd 100644 --- a/receiver/kafkareceiver/kafka_receiver.go +++ b/receiver/kafkareceiver/kafka_receiver.go @@ -157,9 +157,8 @@ func createKafkaClient(config Config) (sarama.ConsumerGroup, error) { return sarama.NewConsumerGroup(config.Brokers, config.GroupID, saramaConfig) } -func (c *kafkaTracesConsumer) Start(_ context.Context, host component.Host) error { - ctx, cancel := context.WithCancel(context.Background()) - c.cancelConsumeLoop = cancel +func (c *kafkaTracesConsumer) Start(ctx context.Context, host component.Host) error { + ctx, c.cancelConsumeLoop = context.WithCancel(ctx) obsrecv, err := receiverhelper.NewObsReport(receiverhelper.ObsReportSettings{ ReceiverID: c.settings.ID, Transport: transport,