Skip to content

[8.19] [Core] Fix KibanaRequest aborted$ never emitting for HTTP/2 requests (#285244) - #285403

Merged
legrego merged 2 commits into
elastic:8.19from
legrego:backport/8.19/pr-285244
Aug 19, 2026
Merged

[8.19] [Core] Fix KibanaRequest aborted$ never emitting for HTTP/2 requests (#285244)#285403
legrego merged 2 commits into
elastic:8.19from
legrego:backport/8.19/pr-285244

Conversation

@legrego

@legrego legrego commented Aug 17, 2026

Copy link
Copy Markdown
Member

Backport

This will backport the following commits from main to 8.19:

Questions ?

Please refer to the Backport tool documentation

…lastic#285244)

## Human summary

Improves the detection of completed requests by additionally checking
for `res.writableEnded`. This works around a quirk in Node.js when
running in http/2, which is resolved in 26+:
nodejs/node#63249.

Checking for `res.writableEnded` does not change anything when running
in http/1, as this is always true when `res.writableFinished`. This
changes behavior for http/2 by properly detecting aborted requests.

This should result in downstream consumers having a more reliable signal
for when a client request is aborted, allowing them to cancel jobs such
as in-flight ES requests regardless of http protocol.

We detected this while writing scout tests for
elastic#285153

## AI description
When an HTTP/2 client destroys a stream mid-request (RST_STREAM /
NGHTTP2_CANCEL, e.g. an AbortController cancel or browser navigation),
Node's Http2ServerResponse emits 'close' with writableFinished === true
even though nothing was written. isCompleted() relied on
writableFinished alone, so the !isCompleted filter swallowed the event
and request.events.aborted$ never fired — consumers (route handlers,
auth providers) could not observe HTTP/2 client aborts. HTTP/1 was
unaffected because writableFinished stays false there.

Treat a request as completed only when writableFinished &&
writableEnded: writableEnded only becomes true once the server actually
ended the response, and is truthful on both protocols and for abrupt
TCP-level disconnects.

Adds integration coverage in http2_protocol.test.ts driving a real
HTTP/2 TLS session that resets the stream while the handler is pending,
plus a control test asserting completed$ (and not aborted$) on normal
completion.

Co-authored-by: Claude Fable 5 <[email protected]>
(cherry picked from commit a19e27a)

# Conflicts:
#	src/core/server/integration_tests/http/http2_protocol.test.ts
@legrego
legrego requested a review from kibanamachine as a code owner August 17, 2026 13:18
@legrego legrego added the backport This PR is a backport of another PR label Aug 17, 2026
@legrego
legrego enabled auto-merge (squash) August 17, 2026 13:18
@kibanamachine
kibanamachine requested review from Bamieh and removed request for kibanamachine August 17, 2026 13:18
@kibanamachine

Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Metrics [docs]

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
kbnUiSharedDeps-srcJs 3.6MB 3.6MB -127.0B

History

@legrego
legrego merged commit 3f4fc0f into elastic:8.19 Aug 19, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants