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 aborted$ event and add completed$ event to KibanaRequest #73898

Merged
merged 1 commit into from
Jul 31, 2020

Conversation

joshdover
Copy link
Contributor

@joshdover joshdover commented Jul 30, 2020

Summary

Fixes the aborted$ event by making sure the Observable does not complete until after the response has been sent. Prior to this change it was possible for the aborted$ Observable to complete prematurely when a POST request was received on a route that had body validation.

Also exposes a proper completed$ event that will emit once whenever the request is aborted or a response has been sent to the client.

Plugin API changes

The request.events.aborted$ Observable will now properly wait for the response to be sent before completing.

A new request.events.completed$ API is available that will emit once a request has been completely handled or aborted.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@joshdover joshdover added bug Fixes for quality problems that affect the customer experience Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. v7.10.0 v7.9.0 labels Jul 30, 2020
@joshdover joshdover requested review from nchaulet and mshustov July 30, 2020 22:07
@joshdover joshdover requested a review from a team as a code owner July 30, 2020 22:07
@elasticmachine
Copy link
Contributor

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

@@ -186,11 +196,16 @@ export class KibanaRequest<

private getEvents(request: Request): KibanaRequestEvents {
const finish$ = merge(
fromEvent(request.raw.req, 'end'), // all data consumed
Copy link
Contributor

@mshustov mshustov Jul 31, 2020

Choose a reason for hiding this comment

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

The initial implementation was based on nodejs/node#21705 discussion and asserted by test #55061 (comment), showing that Request.end happens after Response.finish, even though it shouldn't. I mistakenly assumed the fact that this behavior is consistent across all requests.
2020-07-31_09-02-11

fromEvent(request.raw.req, 'close') // connection was closed
).pipe(shareReplay(1), first());

const aborted$ = fromEvent<void>(request.raw.req, 'aborted').pipe(first(), takeUntil(finish$));
const completed$ = merge<void, void>(finish$, aborted$).pipe(shareReplay(1), first());
Copy link
Contributor

Choose a reason for hiding this comment

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

That's becoming complicated 😓

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Open to any ideas on how to improve, but this seemed the most clear for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.9.0 v7.10.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants