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

[Elastic Agent] Await execution finish on windows #27730

Merged
merged 2 commits into from
Sep 3, 2021

Conversation

michalpristas
Copy link
Contributor

What does this PR do?

The problem is described in issue: #27527
When user wants to stop the service using service manager, error is returned about unexpected termination and agent is restarted.

Reason for this is that agent won't send stopped state to service manager before termination.
In our codebase we use NotifyTermination provided by libbeat on exit. This closes channel and exits the state loop running in a separate goroutine which then should send the stopped state to service manager.
The problem is when we exit right after this call and too quickly. In this case goroutine wont reach the point where stopped is sent and service manager gets the impression we crashed.

To fix this we just need to make sure that svc.Run in libbeat/service/service_windows.go is finished before exiting. Usually it just takes few milliseconds to finish the process but 500 millisecond limit is there to prevent process getting stuck in case something goes wrong.

Why is it important?

Fixes: #27527

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.

@michalpristas michalpristas added bug Team:Elastic-Agent Label for the Agent team backport-v7.15.0 Automated backport with mergify backport-v7.16.0 Automated backport with mergify labels Sep 3, 2021
@michalpristas michalpristas self-assigned this Sep 3, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/agent (Team:Agent)

@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 Sep 3, 2021
@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2021-09-03T08:00:34.748+0000

  • Duration: 165 min 58 sec

  • Commit: 59bd48f

Test stats 🧪

Test Results
Failed 0
Passed 53773
Skipped 5325
Total 59098

Trends 🧪

Image of Build Times

Image of Tests

💚 Flaky test report

Tests succeeded.

Expand to view the summary

Test stats 🧪

Test Results
Failed 0
Passed 53773
Skipped 5325
Total 59098

Copy link
Contributor

@blakerouse blakerouse left a comment

Choose a reason for hiding this comment

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

Nice! Looks good.

@michalpristas michalpristas merged commit 2f897aa into elastic:master Sep 3, 2021
mergify bot pushed a commit that referenced this pull request Sep 3, 2021
* Await execution finish on windows

* don't wait if not running as a service

(cherry picked from commit 2f897aa)
mergify bot pushed a commit that referenced this pull request Sep 3, 2021
* Await execution finish on windows

* don't wait if not running as a service

(cherry picked from commit 2f897aa)
michalpristas added a commit that referenced this pull request Sep 6, 2021
* Await execution finish on windows

* don't wait if not running as a service

(cherry picked from commit 2f897aa)

Co-authored-by: Michal Pristas <michal.pristas@gmail.com>
michalpristas added a commit that referenced this pull request Sep 6, 2021
* Await execution finish on windows

* don't wait if not running as a service

(cherry picked from commit 2f897aa)

Co-authored-by: Michal Pristas <michal.pristas@gmail.com>
@dikshachauhan-qasource
Copy link

Hi @michalpristas

We attempted to validate above PR on 7.15.0-snapshot on windows 10 machine and found it fixed now.

  • We are now able to stop elastic agent service.

Build details:
BUILD 43944
COMMIT 951240e085cc4465167ab4d6bcdf6f267446a874

Screenshot:
image

Thanks
QAS

Icedroid pushed a commit to Icedroid/beats that referenced this pull request Nov 1, 2021
* Await execution finish on windows

* don't wait if not running as a service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v7.15.0 Automated backport with mergify backport-v7.16.0 Automated backport with mergify bug Team:Elastic-Agent Label for the Agent team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Agent] Unable to Stop elastic-agent service from Services manager.
4 participants