Fix aborted$ event and add completed$ event to KibanaRequest#73898
Merged
joshdover merged 1 commit intoelastic:masterfrom Jul 31, 2020
Merged
Fix aborted$ event and add completed$ event to KibanaRequest#73898joshdover merged 1 commit intoelastic:masterfrom
joshdover merged 1 commit intoelastic:masterfrom
Conversation
Contributor
|
Pinging @elastic/kibana-platform (Team:Platform) |
mshustov
reviewed
Jul 31, 2020
|
|
||
| private getEvents(request: Request): KibanaRequestEvents { | ||
| const finish$ = merge( | ||
| fromEvent(request.raw.req, 'end'), // all data consumed |
Contributor
There was a problem hiding this comment.
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.

mshustov
reviewed
Jul 31, 2020
| ).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()); |
Contributor
There was a problem hiding this comment.
That's becoming complicated 😓
Contributor
Author
There was a problem hiding this comment.
Open to any ideas on how to improve, but this seemed the most clear for now.
mshustov
approved these changes
Jul 31, 2020
nchaulet
approved these changes
Jul 31, 2020
This was referenced Jul 31, 2020
joshdover
added a commit
to joshdover/kibana
that referenced
this pull request
Jul 31, 2020
joshdover
added a commit
to joshdover/kibana
that referenced
this pull request
Jul 31, 2020
joshdover
added a commit
that referenced
this pull request
Jul 31, 2020
joshdover
added a commit
that referenced
this pull request
Jul 31, 2020
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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