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

Avoid race condition between HttpServer.stop() and HttpServerSetup methods #64487

Merged
merged 1 commit into from
Apr 30, 2020

Conversation

joshdover
Copy link
Contributor

@joshdover joshdover commented Apr 26, 2020

Summary

Fixes #64381
Fixes #64480

This change should reduce flakiness in integration tests. The issue that appeared to be causing other integration tests to fail was a situation where the server would start stopping before setup had completed, causing some HttpServiceSetup methods to fail.

I attempted writing a high-level test for executing stop at different points in the setup lifecycle, but I was unable to find a practical way of doing so that wasn't highly specific the one known scenario. The challenge is in controlling the execution of the various promises that are resolved during setup to insert the stop call at the specific point that could cause failure.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

Comment on lines 196 to 204
public async stop() {
this.stopped = true;
if (this.server === undefined) {
return;
}

this.log.debug('stopping http server');
await this.server.stop();
this.server = undefined;
}
Copy link
Contributor

@pgayvallet pgayvallet Apr 27, 2020

Choose a reason for hiding this comment

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

Would it be too pragmatic to have stop await a promise that would be resolved at the end of start?
Are there practical use cases where stop should be called before setup/start are completed (if they were invoked).

In most graceful shutdown implementations I'm aware of, this is what is actually done (either this or signal-based cancelation request/awaiting, which is definitely cleaner but also approximatively 42 times harder to implement correctly).

This should probably be done in both core's main Server and I guess HttpServer for ITs.

setup() {
  this.startingPromise = new Promise();
  // do setup
}

start() {
   // do start
   this.startingPromise.resolve(); // yea I know, this doesn't work like that. You get the idea.
}

stop() {
   if(this.startingPromise) {
      await this.startingPromise()
   }
  // do stop
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, I will try that tomorrow.

Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect there will be a lot of complaints that Kibana doesn't react to the stop signal and continue working. But 👍 as a temporary solution.

Copy link
Contributor

@spalger spalger left a comment

Choose a reason for hiding this comment

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

LGTM

@joshdover
Copy link
Contributor Author

@pgayvallet @restrry I have changed this to use Pierre's suggestion and wait for start to complete before stopping continues.

@joshdover joshdover added Feature:New Platform release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.8.0 labels Apr 29, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform (Team:Platform)

@joshdover joshdover marked this pull request as ready for review April 29, 2020 17:13
@joshdover joshdover requested a review from a team as a code owner April 29, 2020 17:13
@joshdover joshdover changed the title Avoid race condition between HttpServer.stop() and HttpServerSetup methods Wait to stop Core server until after start has completed Apr 29, 2020
@joshdover
Copy link
Contributor Author

This other solution is going to take more time than I have right now to work on this. Rolling back to the previous solution and will merge once CI is green.

@joshdover joshdover changed the title Wait to stop Core server until after start has completed Avoid race condition between HttpServer.stop() and HttpServerSetup methods Apr 30, 2020
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

  • 💚 Build #43262 succeeded d54fec91cd40159d25fc1f33a89433c89a775468

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:New Platform release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.8.0
Projects
None yet
6 participants