Skip to content

Do the abort steps of ReadableStreamPipeTo really guarantee the abort callback to be called before cancel? #1229

@saschanaz

Description

@saschanaz

Step 14 of the https://streams.spec.whatwg.org/#readable-stream-pipe-to is basically Promise.all([dest.abort(), source.cancel()]), assuming the states are writable/readable respectively. One WPT test for this asserts that abort() is called before cancel(): https://github.com/web-platform-tests/wpt/blob/285addceabb4443562a9b93d789b17230c3d6e20/streams/piping/abort.any.js#L215-L237

Blink passes this test, but not sure how. A slightly modified test without AbortSignal shows that the abort callback is called after the cancel callback (because the latter is called synchronously while the former is not), so I'd expect same for the AbortSignal test:

promise_test(t => {
  const events = [];
  const rs = new ReadableStream({
    pull(controller) {
      controller.error('failed to abort');
    },
    cancel() {
      events.push('cancel');
      return Promise.reject(error1);
    }
  }, hwm0);
  const ws = new WritableStream({
    abort() {
      events.push('abort');
      return Promise.reject(error2);
    }
  });
  return promise_rejects_exactly(t, error1, Promise.all([ws.abort(), rs.cancel()]), 'The cancel rejection happens first in this case')
      .then(() => assert_array_equals(events, ['cancel', 'abort'], 'cancel() is called first in this case'));
}, '');

Am I understanding something wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions