Skip to content

Commit 19cb1f3

Browse files
committed
always finish subscription
1 parent 45142cf commit 19cb1f3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/core/server/http/router/request.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
import { Url } from 'url';
2121
import { Request } from 'hapi';
22-
import { Observable, fromEvent } from 'rxjs';
23-
import { first, takeUntil } from 'rxjs/operators';
22+
import { Observable, fromEvent, merge } from 'rxjs';
23+
import { shareReplay, first, takeUntil } from 'rxjs/operators';
2424

2525
import { deepFreeze, RecursiveReadonly } from '../../../utils';
2626
import { Headers } from './headers';
@@ -160,9 +160,12 @@ export class KibanaRequest<
160160
}
161161

162162
private getEvents(request: Request): KibanaRequestEvents {
163-
const end$ = fromEvent<void>(request.raw.req, 'end').pipe(first());
163+
const finish$ = merge(
164+
fromEvent(request.raw.req, 'end'), // all data consumed
165+
fromEvent(request.raw.req, 'close') // connection was closed
166+
).pipe(shareReplay(1), first());
164167
return {
165-
aborted$: fromEvent<void>(request.raw.req, 'aborted').pipe(first(), takeUntil(end$)),
168+
aborted$: fromEvent<void>(request.raw.req, 'aborted').pipe(first(), takeUntil(finish$)),
166169
} as const;
167170
}
168171

0 commit comments

Comments
 (0)