Skip to content

HCM: buffered data ignored when onData never returns StopIteration #7579

@snowp

Description

@snowp

If any encodeData callbacks call addEncodedData and no StopIteration* return values are returned, the buffered data will never be read, as we never call commonContinue due to the iteration_state_ check in commonHandleAfterDataCallback:

  if (status == FilterDataStatus::Continue) {
    if (iteration_state_ == IterationState::StopSingleIteration) {
      commonHandleBufferData(provided_data);
      commonContinue();
      return false;
    } else {
      ASSERT(headers_continued_);
    }

This becomes problematic because the following code misbehaves when there's only one encodeData callback:

  Http::FilterDataStatus encodeData(Buffer::Instance& data, bool end_stream) {
    encoder_callbacks_->addEncodedData(data, false);

    if (end_stream) {
      encoder_callbacks_->modifyEncodingBuffer([](auto& buffer) {
        // do something with the buffer
      });
      return Http::FilterDataStatus::Continue;
    }

    return Http::FilterDataStatus::StopIterationNoBuffer;
  }
};

Since the first call is has end_stream = true, we add data to buffer but since we return Continue, the buffer is never passed to the next filter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions