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

Cherry-pick #18916 to 7.8: Windows: fix service termination #19013

Merged
merged 1 commit into from
Jun 8, 2020

Conversation

adriansr
Copy link
Contributor

@adriansr adriansr commented Jun 5, 2020

Cherry-pick of PR #18916 to 7.8 branch. Original message:

What does this PR do?

Update the Windows service handling logic so that the service doesn't transition to the STOPPED state until the beater is terminated. Right now it transitions just after receiving the stop signal. When restarted, this means that a new Beat process is run while the previous is terminating.

Why is it important?

Since #14069 was merged, now Beats randomly fail restarting under Windows, when run as a service. This isn't caused by the previous PR, but a long standing issue with how the service state is handled.

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.

Testing

To reproduce the bug this fixes, you just have to restart a Beats service.

PS> restart-service winlogbeat

It will fail because the already running service transitions to STOPPED while it still terminating. A new service will be executed while the data dir is still locked by the terminating Beat.

This is easy to reproduce with Winlogbeat with default config, maybe not so easy with other Beats as it depends on how long it takes to terminate the running service.

Related issues

Fixes #18914

Update the Windows service handling logic so that the service doesn't
transition to the STOPPED state until the beater is terminated.

Before this patch, a Beats service would report to be STOPPED as soon
as it received the stop request. This causes some problems during service
restarts, as the new service would start while the old one was still cleaning
up.

Fixes elastic#18914

(cherry picked from commit f3ab7c7)
@elasticmachine
Copy link
Collaborator

Pinging @elastic/siem (Team:SIEM)

@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 Jun 5, 2020
@elasticmachine
Copy link
Collaborator

💔 Build Failed

Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: [Started by user Adrian Serrano, Replayed #1]

  • Start Time: 2020-06-08T14:04:01.604+0000

  • Duration: 67 min 18 sec

Test stats 🧪

Test Results
Failed 0
Passed 6203
Skipped 1042
Total 7245

Steps errors

Expand to view the steps failures

  • Name: Make -C filebeat testsuite

    • Description: make -C filebeat testsuite

    • Duration: 7 min 45 sec

    • Start Time: 2020-06-08T14:28:06.825+0000

    • log

  • Name: Make -C libbeat testsuite

    • Description: make -C libbeat testsuite

    • Duration: 7 min 18 sec

    • Start Time: 2020-06-08T14:28:11.040+0000

    • log

Log output

Expand to view the last 100 lines of log output

[2020-06-08T15:10:53.340Z] + curl -sSLo codecov https://codecov.io/bash
[2020-06-08T15:10:53.606Z] + FILE=auditbeat/build/coverage/full.cov
[2020-06-08T15:10:53.607Z] + [ -f auditbeat/build/coverage/full.cov ]
[2020-06-08T15:10:53.607Z] + FILE=filebeat/build/coverage/full.cov
[2020-06-08T15:10:53.607Z] + [ -f filebeat/build/coverage/full.cov ]
[2020-06-08T15:10:53.607Z] + FILE=heartbeat/build/coverage/full.cov
[2020-06-08T15:10:53.607Z] + [ -f heartbeat/build/coverage/full.cov ]
[2020-06-08T15:10:53.607Z] + FILE=libbeat/build/coverage/full.cov
[2020-06-08T15:10:53.607Z] + [ -f libbeat/build/coverage/full.cov ]
[2020-06-08T15:10:53.607Z] + FILE=metricbeat/build/coverage/full.cov
[2020-06-08T15:10:53.607Z] + [ -f metricbeat/build/coverage/full.cov ]
[2020-06-08T15:10:53.607Z] + FILE=packetbeat/build/coverage/full.cov
[2020-06-08T15:10:53.607Z] + [ -f packetbeat/build/coverage/full.cov ]
[2020-06-08T15:10:53.607Z] + FILE=winlogbeat/build/coverage/full.cov
[2020-06-08T15:10:53.607Z] + [ -f winlogbeat/build/coverage/full.cov ]
[2020-06-08T15:10:53.607Z] + FILE=journalbeat/build/coverage/full.cov
[2020-06-08T15:10:53.607Z] + [ -f journalbeat/build/coverage/full.cov ]
[2020-06-08T15:10:54.979Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats
[2020-06-08T15:10:55.286Z] + find . -type f -name TEST*.xml -path */build/* -delete
[2020-06-08T15:10:55.299Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Lint
[2020-06-08T15:10:55.376Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Winlogbeat-oss
[2020-06-08T15:10:55.444Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Elastic-Agent-x-pack
[2020-06-08T15:10:55.511Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Dockerlogbeat
[2020-06-08T15:10:55.586Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Journalbeat-oss
[2020-06-08T15:10:55.655Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Functionbeat-x-pack
[2020-06-08T15:10:55.728Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Generators-Metricbeat-Linux
[2020-06-08T15:10:55.793Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Filebeat-oss
[2020-06-08T15:10:55.860Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Elastic-Agent-x-pack-Windows
[2020-06-08T15:10:55.929Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Libbeat-oss
[2020-06-08T15:10:55.995Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Metricbeat-crosscompile
[2020-06-08T15:10:56.062Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Metricbeat-OSS-Unit-tests
[2020-06-08T15:10:56.130Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Heartbeat-oss
[2020-06-08T15:10:56.197Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Auditbeat-x-pack
[2020-06-08T15:10:56.266Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Libbeat-x-pack
[2020-06-08T15:10:56.333Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Auditbeat-Linux
[2020-06-08T15:10:56.409Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Filebeat-x-pack-Windows
[2020-06-08T15:10:56.490Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Packetbeat-oss
[2020-06-08T15:10:56.558Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Filebeat-Windows
[2020-06-08T15:10:56.628Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Winlogbeat-Windows-x-pack
[2020-06-08T15:10:56.696Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Auditbeat-crosscompile
[2020-06-08T15:10:56.768Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Winlogbeat-Windows
[2020-06-08T15:10:56.835Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Filebeat-x-pack
[2020-06-08T15:10:56.901Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Metricbeat-x-pack-Windows
[2020-06-08T15:10:56.973Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Metricbeat-Windows
[2020-06-08T15:10:57.040Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Functionbeat-Windows
[2020-06-08T15:10:57.112Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Generators-Beat-Linux
[2020-06-08T15:10:57.177Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Heartbeat-Windows
[2020-06-08T15:10:57.249Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Auditbeat-Windows
[2020-06-08T15:10:57.321Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Metricbeat-Python-integration-tests
[2020-06-08T15:10:57.387Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Metricbeat-x-pack
[2020-06-08T15:10:57.454Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Metricbeat-OSS-Integration-tests
[2020-06-08T15:10:57.811Z] + cat
[2020-06-08T15:10:57.811Z] + /usr/local/bin/runbld ./runbld-script
[2020-06-08T15:10:57.811Z] Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
[2020-06-08T15:11:04.421Z] runbld>>> runbld started
[2020-06-08T15:11:04.421Z] runbld>>> 1.6.11/a66728ff8f4356963772e6e6d2069392fa06acbe
[2020-06-08T15:11:06.340Z] runbld>>> The following profiles matched the job 'Beats/beats-beats-mbp/PR-19013' in order of occurrence in the config (last value wins).
[2020-06-08T15:11:07.727Z] runbld>>> Debug logging enabled.
[2020-06-08T15:11:07.727Z] runbld>>> Storing result
[2020-06-08T15:11:07.727Z] runbld>>> Store result: created {:total 2, :successful 2, :failed 0} 1
[2020-06-08T15:11:07.727Z] runbld>>> BUILD: https://c150076387b5421f9154dfbf536e5c60.us-west1.gcp.cloud.es.io:9243/build-1587637540455/t/20200608151107-32967F3C
[2020-06-08T15:11:07.727Z] runbld>>> Adding system facts.
[2020-06-08T15:11:08.671Z] runbld>>> Adding vcs info for the latest commit:  fc4a2a36f231d254c8b500655ef10d8e233ba309
[2020-06-08T15:11:08.939Z] runbld>>> >>>>>>>>>>>> SCRIPT EXECUTION BEGIN >>>>>>>>>>>>
[2020-06-08T15:11:08.940Z] runbld>>> Adding /usr/lib/jvm/java-8-openjdk-amd64/bin to the path.
[2020-06-08T15:11:09.202Z] + echo 'Processing JUnit reports with runbld...'
[2020-06-08T15:11:09.202Z] Processing JUnit reports with runbld...
[2020-06-08T15:11:09.463Z] runbld>>> <<<<<<<<<<<< SCRIPT EXECUTION END <<<<<<<<<<<<
[2020-06-08T15:11:09.463Z] runbld>>> DURATION: 23ms
[2020-06-08T15:11:09.463Z] runbld>>> STDOUT: 40 bytes
[2020-06-08T15:11:09.463Z] runbld>>> STDERR: 49 bytes
[2020-06-08T15:11:09.463Z] runbld>>> WRAPPED PROCESS: SUCCESS (0)
[2020-06-08T15:11:09.463Z] runbld>>> Searching for build metadata in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats
[2020-06-08T15:11:10.851Z] runbld>>> Storing build metadata: 
[2020-06-08T15:11:10.851Z] runbld>>> Adding test report.
[2020-06-08T15:11:10.851Z] runbld>>> Searching for junit test output files with the pattern: TEST-.*\.xml$ in: /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats
[2020-06-08T15:11:11.795Z] runbld>>> Found 95 test output files
[2020-06-08T15:11:12.058Z] runbld>>> No testsuite node found in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Metricbeat-OSS-Integration-tests/metricbeat/build/TEST-go-integration-graphite.xml
[2020-06-08T15:11:12.320Z] runbld>>> No testsuite node found in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Metricbeat-OSS-Integration-tests/metricbeat/build/TEST-go-integration-windows.xml
[2020-06-08T15:11:12.320Z] runbld>>> No testsuite node found in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Metricbeat-x-pack/x-pack/metricbeat/build/TEST-go-integration-openmetrics.xml
[2020-06-08T15:11:12.320Z] runbld>>> No testsuite node found in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Metricbeat-x-pack/x-pack/metricbeat/build/TEST-go-integration-cloudfoundry.xml
[2020-06-08T15:11:12.320Z] runbld>>> No testsuite node found in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Metricbeat-x-pack/x-pack/metricbeat/build/TEST-go-integration-iis.xml
[2020-06-08T15:11:12.320Z] runbld>>> No testsuite node found in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Metricbeat-x-pack/x-pack/metricbeat/build/TEST-go-integration-istio.xml
[2020-06-08T15:11:12.320Z] runbld>>> No testsuite node found in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Metricbeat-x-pack/x-pack/metricbeat/build/TEST-go-integration-activemq.xml
[2020-06-08T15:11:12.320Z] runbld>>> No testsuite node found in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013/src/github.com/elastic/beats/Metricbeat-x-pack/x-pack/metricbeat/build/TEST-go-integration-tomcat.xml
[2020-06-08T15:11:13.262Z] runbld>>> Test output logs contained: Errors: 0 Failures: 0 Tests: 7095 Skipped: 839
[2020-06-08T15:11:13.523Z] runbld>>> Storing result
[2020-06-08T15:11:13.523Z] runbld>>> FAILURES: 0
[2020-06-08T15:11:13.783Z] runbld>>> Store result: updated {:total 2, :successful 2, :failed 0} 2
[2020-06-08T15:11:13.783Z] runbld>>> BUILD: https://c150076387b5421f9154dfbf536e5c60.us-west1.gcp.cloud.es.io:9243/build-1587637540455/t/20200608151107-32967F3C
[2020-06-08T15:11:13.783Z] runbld>>> Email notification disabled by environment variable.
[2020-06-08T15:11:13.783Z] runbld>>> Slack notification disabled by environment variable.
[2020-06-08T15:11:19.289Z] Running on Jenkins in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-19013
[2020-06-08T15:11:19.387Z] [INFO] getVaultSecret: Getting secrets
[2020-06-08T15:11:19.438Z] Masking supported pattern matches of $VAULT_ADDR or $VAULT_ROLE_ID or $VAULT_SECRET_ID
[2020-06-08T15:11:20.125Z] + chmod 755 generate-build-data.sh
[2020-06-08T15:11:20.125Z] + ./generate-build-data.sh https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats-beats-mbp/PR-19013/ https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats-beats-mbp/PR-19013/runs/2 FAILURE 4038261
[2020-06-08T15:11:20.125Z] INFO: curl https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats-beats-mbp/PR-19013/runs/2/steps/?limit=10000 -o steps-info.json
[2020-06-08T15:11:21.469Z] INFO: curl https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats-beats-mbp/PR-19013/runs/2/tests/?status=FAILED -o tests-errors.json
[2020-06-08T15:11:21.469Z] INFO: curl https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats-beats-mbp/PR-19013/runs/2/log/ -o pipeline-log.txt

@adriansr adriansr merged commit a1f66e0 into elastic:7.8 Jun 8, 2020
@adriansr adriansr deleted the backport_18916_7.8 branch June 8, 2020 15:49
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.

None yet

3 participants