immich-app / immich

High performance self-hosted photo and video management solution.
https://immich.app
GNU Affero General Public License v3.0
40.03k stars 1.95k forks source link

Downloading large album fails in webapp on devices with limited memory #7542

Open kamzil opened 4 months ago

kamzil commented 4 months ago

The bug

When I try to download an album from the webapp on either Firefox or Brave browser on Android, the app first displays a progress bar that says "Downloading".

I think how this works is it's actually streaming the zip into the browser's memory, and only after it's finished, it will start "downloading" the file to the storage, rather than behaving like a normal browser file download where file is streamed to the device's storage from the start. Maybe the device's RAM gets too full and Firefox gets killed. This doesn't appear to be a very scalable way of downloading large files, as mobile apps are often very restricted on RAM usage.

Looking at the source code, it seems to stream the data from the server into a client-side blob and only then opening it as a link to initiate the browser download functionality to save it to the storage.

The OS that Immich Server is running on

Docker

Version of Immich Server

v1.96.0

Version of Immich Mobile App

Web

Platform with the issue

Your docker-compose.yml content

.

Your .env content

.

Reproduction steps

1. Create album with lots of photos
2. Click download icon from the album view in webapp on device with limited memory
3. App gets killed because of too high memory usage

Additional information

No response

kamzil commented 4 months ago

In immich-server container log when the Brave error happens:

  ERROR [StreamableFile] Premature close 
Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close
    at ServerResponse.onclose (node:internal/streams/end-of-stream:159:30)
    at ServerResponse.emit (node:events:530:35)
    at emitCloseNT (node:_http_server:1031:10)
    at Socket.onServerResponseClose (node:_http_server:278:5)
    at Socket.emit (node:events:530:35)
    at TCP.<anonymous> (node:net:337:12)
Ynng commented 1 month ago

I'm getting the same error when downloading a 4GB album. The problem only occur in Edge on windows. Re-attempting the download in Firefox worked.

[Nest] 7  - 05/27/2024, 11:14:38 PM   ERROR [ImmichServer] [StreamableFile] Premature close
Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close
    at ServerResponse.onclose (node:internal/streams/end-of-stream:159:30)
    at /usr/src/app/node_modules/@opentelemetry/context-async-hooks/build/src/AbstractAsyncHooksContextManager.js:50:55
    at AsyncLocalStorage.run (node:async_hooks:346:14)
    at AsyncLocalStorageContextManager.with (/usr/src/app/node_modules/@opentelemetry/context-async-hooks/build/src/AsyncLocalStorageContextManager.js:33:40)
    at ServerResponse.contextWrapper (/usr/src/app/node_modules/@opentelemetry/context-async-hooks/build/src/AbstractAsyncHooksContextManager.js:50:32)
    at ServerResponse.emit (node:events:531:35)
    at emitCloseNT (node:_http_server:1020:10)
    at Socket.onServerResponseClose (node:_http_server:278:5)
    at Socket.emit (node:events:531:35)
    at TCP.<anonymous> (node:net:338:12)

image

cedarwu commented 1 week ago

I'm getting the same error when downloading a 1GB video. I tried both iOS app and browser. The version of iOS app is 1.108.0 build.163, and the error log follows: image