-
Notifications
You must be signed in to change notification settings - Fork 161
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
Handling stream errors in a TransformStream transformer #1212
Comments
A |
We assume that Similarly, we assume that errors thrown (or promises rejected) from within a sink method were already handled by that sink method (e.g. with a
That said, I do agree with the OP: cancelling the readable end and/or aborting the writable end of a transform stream should call some sort of |
Yeah, I think this is especially acute for transformers. In the previous discussions it was more "it's awkward to know where to put your cleanup logic"; for transforms it seems like "there's nowhere to put your cleanup logic". |
@domenic That's exactly right. This is actually getting more and more pressing by the day. I'll see if we can allocate some resources to open a PR for this. I guess the proposed solution right now is to add a |
Definite +1 to a |
Wow, I'm surprised about this omission, making it impossible for |
The background to this is that I found a bug in deno's
TextDecoderStream
implementation that results in it failing to clean up a resource it holds if its stream pipeline aborts with an error. The implementation holds aTextDecoder
which it uses in streaming mode. TheTextDecoder
holds a resource handle to a native object handling text decoding for it, which it closes whendecode()
is called without{stream: true}
. When the denoTextDecoderStream
implementation's transformer gets aflush()
call, it callsdecode()
to close theTextDecoder
. However, if the stream aborts,flush()
is not called, so the native resource handle is not closed, and gets leaked.I've looked through the Streams spec, and as I understand it there's no built-in way for a transformer to be notified of a stream error.
It is possible to work around this as an API user, as I mention in the deno issue:
Although I say "fairly straightforward", it's not exactly trivial. And another alternative of not using
TransformStream
and instead tying together a readable and writable stream manually to create a (readable, writable) pair is even more fiddly to do correctly.As an API user, it seems like there should be an idiomatic way to handle stream errors in a transformer. The underlying sink of a
WritableStream
can do so either with itsabort()
method, or via theAbortSignal
onWritableStreamDefaultController
'ssignal
property.What do you think about giving transformers similar capabilities to handle aborts as underlying sinks?
Even just giving
TransformStreamDefaultController
anAbortSignal
would be helpful (I presume that's simpler to spec than a method on transformer, as it can't affect the error propagation behaviour). Although I suppose a method would allow for asynchronous cleanup...The text was updated successfully, but these errors were encountered: