google-cloud-cpp: ReadObject with empty or small range results in error

Does this issue affect the google-cloud-cpp project? If the problem is with the Google Cloud service exposed by the google-cloud-cpp libraries instead of the client libraries themselves, you may consider opening a support request instead. The google-cloud-cpp developers cannot help you troubleshoot problems with the service itself.

Doing read_stream.status().message.data() returns 0x7fffeef27558 std::string::_Rep::_S_empty_rep_storage+24 “” I suspect this is SDK issue.

What component of google-cloud-cpp is this related to? For example, is this related to bigtable (i.e., something in google/cloud/bigtable), or GCS (i.e., something in google/cloud/storage)?

Storage

Describe the bug A clear and concise description of what the bug is.

If I run ReadObject on a zero sized object, error is set on stream with empty buffer in status.

To Reproduce Steps to reproduce the behavior:

  1. Create empty/0 byte object.
  2. gcs::ObjectReadStream read_stream = client.ReadObject(_bucket_name.data(), _object_name.data(), gcs::ReadRange(start, start+readsize)); where readsize is 0.
  3. Check read_stream && read_stream.IsOpen()
  4. Obtain read_stream.status().message().data()

Expected behavior A clear and concise description of what you expected to happen. My expectations are:

  • If I’m able to create a 0 sized object in store, I should be able to read it. SDK minimally should check if the object is accessible.
  • Even if it decides to set an error, it should be legible message.

Operating system: If you are using a Linux distribution please include the name and version of the distribution too. SUSE Linux Enterprise Server 12 SP4

What compiler and version are you using? Please include the output of g++ -v or clang++ -v or the equivalent command-line flag. cc version 9.2.1 20191018

What version of google-cloud-cpp are you using? Please include the output from git rev-parse HEAD if you are compiling from source, or the version number from the applicable google/cloud/*/version.h file. 1.24

Additional context Add any other context about the problem here.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 25 (13 by maintainers)

Most upvoted comments

Argh, you are correct:

curl -sSL -H "Range: bytes=0-0" -H "Authorization: Bearer $(gcloud auth print-access-token)" https://coryan-test-bucket.storage.googleapis.com/empty.txt
<?xml version='1.0' encoding='UTF-8'?><Error><Code>InvalidRange</Code><Message>The requested range cannot be satisfied.</Message><Details>bytes=0-0</Details></Error>

This works:

curl -sSL -H "Range: bytes=-1" -H "Authorization: Bearer $(gcloud auth print-access-token)" https://coryan-test-bucket.storage.googleapis.com/empty.txt

Which should be implementable using gcs::ReadLast(1) (I have not tested this):

https://googleapis.dev/cpp/google-cloud-storage/latest/structgoogle_1_1cloud_1_1storage_1_1v1_1_1ReadLast.html

It also seems like GCS supports the Range: 1-0 convention:

curl -sSL -H "Range: bytes=1-0" -H "Authorization: Bearer $(gcloud auth print-access-token)" https://coryan-test-bucket.storage.googleapis.com/empty.txt

Seems like I could fix the client library to implement any empty range as Range: bytes=1-0… worth a try.

You could always try to read 1 byte, maybe the first byte. That is about as good as reading 0 bytes performance-wise, and if there are 0 bytes it should work anyway. In fact, I am temped to implement “read 0 bytes” as “read 1 byte but discard the first byte that arrives, if any”.