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

Considering removing AsyncRequest#inputStream() and AsyncResponse#outputStream() #74

Open
alalag1 opened this issue Jul 19, 2021 · 0 comments
Labels
refactor Code change

Comments

@alalag1
Copy link
Member

alalag1 commented Jul 19, 2021

Motivation

AsyncRequest and AsyncResponse provide methods:

  1. AsyncRequest#inputStream() is holding the aggregated body which has been received completely, It doesn't make much sense to do this.
  2. It is hard to be compatible with the InputStream that will block until input data is available, which it may block on the IO EventloopGroup
  3. AsyncResponse#outputStream() is writing bytes asynchronously, which means it is allowed to write bytes very frequently without any check of channel's writability and ByteBufAllocator's allocatability, which may cause an OOM error.
    private void flush(boolean isLast) {
    if (byteBuf.readableBytes() == 0) {
    if (isLast) {
    byteBuf.release();
    }
    return;
    }
    if (isLast) {
    resp.write(byteBuf);
    } else {
    final ByteBuf copy = byteBuf.copy();
    try {
    resp.write(copy);
    } catch (Exception e) {
    copy.release();
    ExceptionUtils.throwException(e);
    } finally {
    byteBuf.clear();
    }
    }
    }
  4. It is hard to be compatible with the OutputStream that will block until output data is writable, which it may block on the IO EventloopGroup
  5. Reactive programing is exactly what we want

What should we do

  1. Remove AsyncRequest#inputStream() and AsyncResponse#outputStream() methods
  2. Supporting reading/writing data reactively
@alalag1 alalag1 added the refactor Code change label Jul 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Code change
Projects
None yet
Development

No branches or pull requests

1 participant