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 memqueue race condition during shutdown #43874

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

faec
Copy link
Contributor

@faec faec commented Apr 11, 2025

The memory queue had a bug where if Close was called on an already-empty queue, it would mark itself as closing but never cancel the final internal context. The main effect was that Get requests to such a queue would still block instead of correctly returning io.EOF immediately. This caused some test flakiness, e.g. TestClient/no_infinite_loop_when_processing_fails depended on the io.EOF return value to end the test, but whether Close was called before or after draining the queue depended on goroutine execution order. This PR moves the context cancellation check to the end of the run loop iteration, so it's updated after every state change and not just after event deletions. The accompanying unit test fails without this change.

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
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

@faec faec added bug Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team labels Apr 11, 2025
@faec faec self-assigned this Apr 11, 2025
@botelastic botelastic bot added needs_team Indicates that the issue/PR needs a Team:* label and removed needs_team Indicates that the issue/PR needs a Team:* label labels Apr 11, 2025
@faec faec marked this pull request as ready for review April 11, 2025 20:49
@faec faec requested a review from a team as a code owner April 11, 2025 20:49
@faec faec requested review from AndersonQ and VihasMakwana April 11, 2025 20:49
@elasticmachine
Copy link
Collaborator

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

Copy link
Contributor

mergify bot commented Apr 11, 2025

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @faec? 🙏.
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.

@faec faec added the backport-active-all Automated backport with mergify to all the active branches label Apr 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-active-all Automated backport with mergify to all the active branches bug 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.

2 participants