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

GCP InputStream in GCP actually readsAllBytes #440

Open
eahrold opened this issue Mar 22, 2024 · 3 comments
Open

GCP InputStream in GCP actually readsAllBytes #440

eahrold opened this issue Mar 22, 2024 · 3 comments
Labels
type: bug Something isn't working

Comments

@eahrold
Copy link
Contributor

eahrold commented Mar 22, 2024

When fetching larger files, we are seeing throwIfFatal detected a jvm fatal exception, which is thrown and logged below: java.lang.OutOfMemoryError: Java heap space

It looks like what's happening is that the underlying method used in objectstorage, is actually just pulling all bytes from the Blob into memory, and not creating a usable stream.

public InputStream getInputStream() {
return new ByteArrayInputStream(blob.getContent());
}

The relevant stack.

        at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:50)
	at com.google.cloud.storage.Retrying.run(Retrying.java:65)
	at com.google.cloud.storage.StorageImpl.run(StorageImpl.java:1527)
	at com.google.cloud.storage.StorageImpl.readAllBytes(StorageImpl.java:622)
	at com.google.cloud.storage.Blob.getContent(Blob.java:778)
	at io.micronaut.objectstorage.googlecloud.GoogleCloudStorageEntry.getInputStream(GoogleCloudStorageEntry.java:50)

What we've got under the hood is similar to this.

7.2. Download endpoint from https://guides.micronaut.io/latest/micronaut-object-storage-gcp-gradle-java.html

@eahrold
Copy link
Contributor Author

eahrold commented Mar 22, 2024

There may be some autoclose foot-guns here, but I've implemented the equivalent of this, and seems to work for files of any size

    @NonNull
    @Override
     public InputStream getInputStream() {
          return Channels.newInputStream(blob.reader());
     }

@alvarosanchez alvarosanchez added bug Something isn't working type: bug Something isn't working and removed bug Something isn't working labels Apr 3, 2024
@alvarosanchez
Copy link
Member

@eahrold thank you very much! Would you be willing to send a PR so that you get credit for the fix?

eahrold pushed a commit to eahrold/micronaut-object-storage that referenced this issue Apr 27, 2024
eahrold pushed a commit to eahrold/micronaut-object-storage that referenced this issue Apr 27, 2024
eahrold pushed a commit to eahrold/micronaut-object-storage that referenced this issue Apr 27, 2024
@eahrold
Copy link
Contributor Author

eahrold commented Apr 27, 2024

@alvarosanchez here you go, #467

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants