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

S3 Invalid Range 416 error when trying to read empty directory #1145

Open
jeet23 opened this issue Jan 17, 2024 · 5 comments
Open

S3 Invalid Range 416 error when trying to read empty directory #1145

jeet23 opened this issue Jan 17, 2024 · 5 comments

Comments

@jeet23
Copy link

jeet23 commented Jan 17, 2024

The readFileMultipart API is unable to read files from an empty directory and errors out with an S3 exception.

Steps to reproduce:
Let's say we have a bucket localbucket has folder called directory but there is no files inside it.

val result = 
  s3.readFileMultipart(
          bucket = BucketName("localbucket"),  
          key = FileKey("localbucket/directory/"),
         partSize = PartSizeMB(25)
  )

Output:

Actual:


software.amazon.awssdk.services.s3.model.S3Exception: 
The requested range is not satisfiable (Service: S3, Status Code: 416, Request ID: xyz, 
Extended Request ID: ...

Expected:
Empty Stream with new Array[Byte](0)

@semenodm
Copy link
Member

Since we don't know if the key is not present in advance, the way to fix this is to check the exception and return an empty stream if the exception indicates a non-existing key. Looking at this exception, it needs to be made clear how to identify that this key does not exist. I want to avoid parsing the exception message to figure it out.

@jeet23
Copy link
Author

jeet23 commented Jan 17, 2024

According to AWS docs, a 416 should be accompanied with InvalidRange error code.

We could catch it like:

case ex: S3Exception =>
   if(ex.awsErrorDetails().errorCode() == "InvalidRange")
      # return empty stream

@semenodm
Copy link
Member

I am not convinced that InvalidRange ALWAYS means no key to read.

@jeet23
Copy link
Author

jeet23 commented Jan 17, 2024

I don't see any other status codes/ error messages in S3 docs that return InvalidRange. Do you have any other ideas @semenodm ?

@jeet23
Copy link
Author

jeet23 commented Feb 6, 2024

@semenodm do you have any updates here?

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

No branches or pull requests

2 participants