-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Conversation
public async stop() { | ||
this.stopped = true; | ||
if (this.server === undefined) { | ||
return; | ||
} | ||
|
||
this.log.debug('stopping http server'); | ||
await this.server.stop(); | ||
this.server = undefined; | ||
} |
There was a problem hiding this comment.
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
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
d54fec9
to
ea4cb3f
Compare
@pgayvallet @restrry I have changed this to use Pierre's suggestion and wait for start to complete before stopping continues. |
Pinging @elastic/kibana-platform (Team:Platform) |
ea4cb3f
to
e34ae40
Compare
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. |
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
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 duringsetup
to insert thestop
call at the specific point that could cause failure.Checklist
Delete any items that are not applicable to this PR.
For maintainers