streams icon indicating copy to clipboard operation
streams copied to clipboard

Should the underlying source be pinged for cancel when a close request exists?

Open saschanaz opened this issue 2 years ago • 1 comments
trafficstars

const stream = new ReadableStream({
  start(c) {
    c.enqueue(new Uint8Array(8));
    c.close();
  },
  cancel() {
    console.log("cancellation happened");
  }
});
stream.cancel();

This calls the cancel callback, and this does not:

const stream = new ReadableStream({
  start(c) {
    c.enqueue(new Uint8Array(8));
    c.close();
  },
  cancel() {
    console.log("cancellation happened");
  }
});
const reader = stream.getReader();
reader.read();
reader.cancel();

... as ReadableStreamCancel does not check [[closeRequested]] in the first example.

I think the underlying source is effectively done at the point it calls controller.close(), is there a reason it should be pinged for anything after that? Probably too late to change the behavior even if there's no need, though.

saschanaz avatar Jan 21 '23 12:01 saschanaz

My interpretation is that in the second case, all the data has been read, so the underlying source doesn't need to know about the cancellation. But in the first case there's potentially been some data loss.

It's probably too late to change the behaviour given how much code has been written against the current semantics.

ricea avatar Jan 24 '23 07:01 ricea