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

Calling sink.abort() after a sink method rejection could lead to double cleanup #735

Open
ricea opened this issue Apr 14, 2017 · 3 comments

Comments

@ricea
Copy link
Collaborator

ricea commented Apr 14, 2017

This was raised by @tyoshino in web-platform-tests/wpt#5421 (comment)

Consider the following sink:

new WritableStream({
  write(chunk) {
    return handle.write(chunk)
        .catch(reason => {
          cleanup();
          return Promise.reject(reason);
        });
  }

  close() {
    handle.flush();
    cleanup();
  }

  abort() {
    cleanup();
  }

  cleanup() {
    handle.close();
  }
});

The author is trying to be diligent in closing the handle whatever happens. But since #721 if writer.abort() is called and then sink.write() fails, cleanup() will be called twice.

My feeling is that while this is unfortunate, the principle that sink.abort() is always called if writer.abort() is called before any other errors on the stream is a good one. I think adding finally() (#636) in V2 will provide a better way to implement the above sink, and until then we don't need to take any action.

I opened this issue to gather other opinions and to track this problem.

@domenic
Copy link
Member

domenic commented Apr 17, 2017

I agree with your feeling. I think in general without finally(), double-cleanup or not-enough-cleanup is a hazard with the current API, and you need to write code resilient to that. I guess we should prioritize finally() a decent bit.

@ricea
Copy link
Collaborator Author

ricea commented Apr 18, 2017

I've been having second thoughts about this. But I really want to provide a stable target in the medium-term for browsers to implement. We could probably keep tweaking things forever if we let ourselves.

If/when browser vendors start complaining about this behaviour, that would be a good time to change it.

@tyoshino
Copy link
Member

Thanks for the feedback, domenic, ricea. I'm fine with the plan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants