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 memory leak caused by taskqueue closing before all tasks are executed #1493

Merged
merged 1 commit into from
Oct 18, 2024

Conversation

ankur22
Copy link
Collaborator

@ankur22 ankur22 commented Oct 18, 2024

What?

Adding a context.Done() check so that when the context is closed we can carry on with shutting down of the iteration and not wait for the task to run (which will not happen since the taskqueue will have also been shutdown either from here, or here).

Why?

If the taskqueue is closed before all the tasks are read from the queue, the remaining tasks on the queue will not be read and executed and so the done channel will not be closed causing the goroutine to wait forever.

Checklist

  • I have performed a self-review of my code
  • I have added tests for my changes
  • I have commented on my code, particularly in hard-to-understand areas

Related PR(s)/Issue(s)

Updates: #1480

@ankur22 ankur22 mentioned this pull request Oct 18, 2024
If the context is done before all the tasks are read from the queue,
the remaining tasks on the queue will not be read and so the done
channel will not be closed causing the goroutine to wait forever.

This is solved by adding a context.Done() check so that when the
context is closed we can carry on with shutting down of the iteration.
@ankur22 ankur22 changed the title Fix memory leak caused by context closing and waiting for the task to complete Fix memory leak caused by taskqueue closing before all tasks are executed Oct 18, 2024
Copy link
Member

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

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

Nice find!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants