Skip to content

[aws-cpp-sdk-s3-crt] downloads fail silently on local or streambuf write error #3824

@grrtrr

Description

@grrtrr

Problem description

When downloading files with the S3CrtClient, write errors to the Aws::Iostream body are ignored (not even logged).
This silent failure is problematic, in particular when using a TransferManager, since it requires external validation to check the transfer.

The problem is that the failbit/badbit are not checked after write/flush:

// generated/src/aws-cpp-sdk-s3-crt/source/S3CrtClient.cpp

int S3CrtClient::S3CrtRequestGetBodyCallback(struct aws_s3_meta_request *meta_request, const struct aws_byte_cursor *body, uint64_t range_start, void *user_data)
{
  AWS_UNREFERENCED_PARAM(range_start);

  auto *userData = static_cast<S3CrtClient::CrtRequestCallbackUserData*>(user_data);
  if (!userData || !userData->response || !userData->request) {
    return AWS_OP_ERR;
  }
  auto& bodyStream = userData->response->GetResponseBody();

  bodyStream.write(reinterpret_cast<char*>(body->ptr), static_cast<std::streamsize>(body->len));
  if (userData->request->IsEventStreamRequest())
  {
    bodyStream.flush();
  }

   // Continues here without checking for errors.
   // ...
}

We realized this while testing downloads in parallel where one of the downloads ran into a streambuf error.

What to do

Check bodyStream.fail() and if true, return AWS_OP_ERR, logging the cause of the error.

AWS CPP SDK version used

Problem is present on main.

Compiler and Version used

clang >= 15

Operating System and version

ubuntu 22.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.pending-releaseThis issue will be fixed by an approved PR that hasn't been released yet.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions