Skip to content

Conversation

@kruskall
Copy link
Member

Proposed commit message

prevent goroutine leak and wait for init to complete when closing the processor

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works. Where relevant, I have used the stresstest.sh script to run them under stress conditions and race detector to verify their stability.
  • I have added an entry in ./changelog/fragments using the changelog tool.

Disruptive User Impact

Author's Checklist

  • [ ]

How to test this PR locally

Related issues

Use cases

Screenshots

Logs

prevent goroutine leak and wait for init to complete when
closing the processor
@kruskall kruskall requested a review from a team as a code owner November 15, 2025 06:21
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Nov 15, 2025
@github-actions
Copy link
Contributor

🤖 GitHub comments

Just comment with:

  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

@mergify
Copy link
Contributor

mergify bot commented Nov 15, 2025

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @kruskall? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit
  • backport-active-all is the label that automatically backports to all active branches.
  • backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
  • backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.

@pierrehilbert pierrehilbert added the Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team label Nov 16, 2025
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Nov 16, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

@pierrehilbert pierrehilbert added needs_team Indicates that the issue/PR needs a Team:* label skip-changelog labels Nov 16, 2025
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Nov 16, 2025
if k.cache != nil {
k.cache.stop()
}
k.initOnce.Do(func() {})
Copy link
Member

@AndersonQ AndersonQ Nov 17, 2025

Choose a reason for hiding this comment

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

Just to double-check, you're trying to avoid the situation where Close is called while init is still executing.
So, in that case, shouldn't this call be the 1st thing, to ensure:

  • close only runs after init has finished
  • close closes all resources init created?

Also, as it not so straight forward to get why it's calling Do with an empty function, I believe it would be good to add a comment here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! 🙇

The goal here is to avoid there are goroutines leaking after close has been called (which can happen if init hasn't finished).
Those are good points, added a comment and updated the code 👍

@kruskall kruskall requested a review from AndersonQ November 19, 2025 05:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changelog Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants