Skip to content

[receiver/kafka] Use proper context for shutdown #35438

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

Closed

Conversation

djaglowski
Copy link
Member

@djaglowski djaglowski commented Sep 26, 2024

The background context was being used to manage a shutdown routine, which means that it will never shut down. This change just uses the correct context, which is passed to Start.

Resolves #30789 again

@djaglowski djaglowski force-pushed the kafka-receiver-context-fix branch from ea6cf95 to 3458d16 Compare September 26, 2024 15:26
@djaglowski djaglowski marked this pull request as ready for review September 26, 2024 15:43
@djaglowski djaglowski requested a review from a team as a code owner September 26, 2024 15:43
Comment on lines +160 to +161
func (c *kafkaTracesConsumer) Start(ctx context.Context, host component.Host) error {
ctx, c.cancelConsumeLoop = context.WithCancel(ctx)
Copy link
Member

@crobert-1 crobert-1 Sep 26, 2024

Choose a reason for hiding this comment

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

Suggested change
func (c *kafkaTracesConsumer) Start(ctx context.Context, host component.Host) error {
ctx, c.cancelConsumeLoop = context.WithCancel(ctx)
func (c *kafkaTracesConsumer) Start(ctx context.Context, host component.Host) error {
ctx, c.cancelConsumeLoop = context.WithCancel(ctx)

I don't think this is the solution here, as it goes against the spec's comments on context usage for components. The comment about Start here says we shouldn't use the passed in context for long-running background operations. At the moment using the passed in context doesn't cause any issues, but we don't want to go against the spec unless there's good reason.

Also, I don't believe this will resolve any kind of stuck shutdown. context.WithCancel creates a child context that can be cancelled independently of the parent. If the parent is shutdown, the child will automatically be shutdown as well, but there's no requirement vice versa. (The child can be shutdown just fine even if the parent is still running.)

I think there's else going on here, but feel free to correct me if I'm missing something here, or if you tested and confirmed this resolved the issue 🙂

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right. Good explanation. I clearly didn't think this through very well.

@djaglowski
Copy link
Member Author

Closing the PR in light of @crobert-1's point.

@djaglowski djaglowski closed this Sep 26, 2024
@djaglowski djaglowski deleted the kafka-receiver-context-fix branch September 26, 2024 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kafka receiver stuck while shutting down at v0.93.0
3 participants