-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Conversation
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 |
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.
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.
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()); |
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.
That's becoming complicated 😓
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.
Open to any ideas on how to improve, but this seemed the most clear for now.
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