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

KTOR-7734 JS: Catch error on channel reader closure #4641

Merged
merged 2 commits into from
Jan 31, 2025

Conversation

osipxd
Copy link
Member

@osipxd osipxd commented Jan 31, 2025

Subsystem
Client (JS/WasmJS)

Motivation
KTOR-7734 "AbortError: BodyStreamBuffer was aborted" error when canceling parent job

Solution
Solution in #4629 wasn’t correct.
The actual root cause of the issue was an uncaught exception thrown inside a Promise returned by reader.cancel(). Added catching for this exception and reformatted code a bit.

It's better to review these two commits separately.

@osipxd osipxd self-assigned this Jan 31, 2025
throw cause
}
}.channel

internal suspend fun ReadableStreamDefaultReader<Uint8Array>.readChunk(): Uint8Array? =
suspendCancellableCoroutine { continuation ->
suspendCoroutine { continuation ->
Copy link
Member Author

Choose a reason for hiding this comment

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

Made this coroutine non-cancellable to ensure the exception thrown on controller.abort() is propagated to the upper level.

@osipxd osipxd enabled auto-merge (squash) January 31, 2025 16:38
Copy link
Contributor

@bjhham bjhham left a comment

Choose a reason for hiding this comment

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

Huzzah!

@osipxd osipxd merged commit c6bdf2b into main Jan 31, 2025
14 of 16 checks passed
@osipxd osipxd deleted the osipxd/abort-controller-abortion branch January 31, 2025 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants