api/assets take 10000 crashes server with out of memory (64gb system) #3052

Closed
opened 2026-02-05 07:33:44 +03:00 by OVERLORD · 1 comment
Owner

Originally created by @Dankni95 on GitHub (May 3, 2024).

The bug

api/asset?skip=10000&take=10000&updatedBefore=2024-05-03T07%3A53%3A04.610024Z&userId=xxxx

Crashes my server,

if i run api call with take 5000 my server does not crash api/asset?skip=10000&take=5000&updatedBefore=2024-05-03T07%3A53%3A04.610024Z&userId=xxxx

It seems to me like JSON.stringify is running out of memory when stringifying too many objects.

More info from other places i have posted this issue:

Im getting this error that crashes immich_server when building the timeline.

04/23/2024
11:06:53 PM
<--- Last few GCs --->
04/23/2024
11:06:53 PM
04/23/2024
11:06:53 PM
[6:0x5d52e330000]   917559 ms: Scavenge (reduce) 2044.8 (2081.5) -> 2044.1 (2081.8) MB, 7.28 / 0.00 ms  (average mu = 0.338, current mu = 0.325) allocation failure; 
04/23/2024
11:06:53 PM
[6:0x5d52e330000]   917618 ms: Scavenge (reduce) 2044.9 (2081.8) -> 2044.2 (2081.8) MB, 5.81 / 0.00 ms  (average mu = 0.338, current mu = 0.325) allocation failure; 
04/23/2024
11:06:53 PM
[6:0x5d52e330000]   917681 ms: Scavenge (reduce) 2045.0 (2081.8) -> 2044.4 (2082.0) MB, 4.54 / 0.00 ms  (average mu = 0.338, current mu = 0.325) allocation failure; 
04/23/2024
11:06:53 PM
04/23/2024
11:06:53 PM
04/23/2024
11:06:53 PM
<--- JS stacktrace --->
04/23/2024
11:06:53 PM
04/23/2024
11:06:53 PM
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
04/23/2024
11:06:53 PM
----- Native stack trace -----
04/23/2024
11:06:53 PM
04/23/2024
11:06:53 PM
 1: 0xb84bd6 node::OOMErrorHandler(char const*, v8::OOMDetails const&) [immich_server]
04/23/2024
11:06:53 PM
 2: 0xefeb90 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [immich_server]
04/23/2024
11:06:53 PM
 3: 0xefee77 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [immich_server]
04/23/2024
11:06:53 PM
 4: 0x1110885  [immich_server]
04/23/2024
11:06:53 PM
 5: 0x1110e14 v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [immich_server]
04/23/2024
11:06:53 PM
 6: 0x1127d04 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::internal::GarbageCollectionReason, char const*) [immich_server]
04/23/2024
11:06:53 PM
 7: 0x112851c v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [immich_server]
04/23/2024
11:06:53 PM
 8: 0x112a67a v8::internal::Heap::HandleGCRequest() [immich_server]
04/23/2024
11:06:53 PM
 9: 0x1095ce7 v8::internal::StackGuard::HandleInterrupts() [immich_server]
04/23/2024
11:06:53 PM
10: 0x1537542 v8::internal::Runtime_StackGuardWithGap(int, unsigned long*, v8::internal::Isolate*) [immich_server]
04/23/2024
11:06:53 PM
11: 0x7fc429e99ef6 

Server crashes before reaching 4.3 gb of ram, when i added- NODE_OPTIONS="--max-old-space-size=24000" it now reaches 8gb on my 64gb system.

With the env variable i got this error:

Nest] 7  - 04/22/2024, 5:51:27 PM   ERROR [ExceptionsHandler] Invalid string length
04/22/2024
07:51:27 PM
RangeError: Invalid string length
04/22/2024
07:51:27 PM
    at JSON.stringify (<anonymous>)
04/22/2024
07:51:27 PM
    at stringify (/usr/src/app/node_modules/express/lib/response.js:1159:12)
04/22/2024
07:51:27 PM
    at ServerResponse.json (/usr/src/app/node_modules/express/lib/response.js:272:14)
04/22/2024
07:51:27 PM
    at ExpressAdapter.reply (/usr/src/app/node_modules/@nestjs/platform-express/adapters/express-adapter.js:62:62)
04/22/2024
07:51:27 PM
    at RouterResponseController.apply (/usr/src/app/node_modules/@nestjs/core/router/router-response-controller.js:15:36)
04/22/2024
07:51:27 PM
    at /usr/src/app/node_modules/@nestjs/core/router/router-execution-context.js:176:48
04/22/2024
07:51:27 PM
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
04/22/2024
07:51:27 PM
    at async /usr/src/app/node_modules/@nestjs/core/router/router-execution-context.js:47:13
04/22/2024
07:51:27 PM
    at async /usr/src/app/node_modules/@nestjs/core/router/router-proxy.js:9:17

This is only for 18k photos for this user, total 30k, 64gb allocated.
Help much appreciated.

The OS that Immich Server is running on

Ubuntu 22.10

Version of Immich Server

latest

Version of Immich Mobile App

latest

Platform with the issue

  • Server
  • Web
  • Mobile

Your docker-compose.yml content

Can post if really needed

Your .env content

no env

Reproduction steps

1. upload 15k assets on web
2. try to build timeline on ios/android
3. or call api `api/asset?skip=10000&take=10000&updatedBefore=2024-05-03T07%3A53%3A04.610024Z&userId=xxxx`
...

Relevant log output

Nest] 7  - 04/22/2024, 5:51:27 PM   ERROR [ExceptionsHandler] Invalid string length
04/22/2024
07:51:27 PM
RangeError: Invalid string length
04/22/2024
07:51:27 PM
    at JSON.stringify (<anonymous>)
04/22/2024
07:51:27 PM
    at stringify (/usr/src/app/node_modules/express/lib/response.js:1159:12)
04/22/2024
07:51:27 PM
    at ServerResponse.json (/usr/src/app/node_modules/express/lib/response.js:272:14)
04/22/2024
07:51:27 PM
    at ExpressAdapter.reply (/usr/src/app/node_modules/@nestjs/platform-express/adapters/express-adapter.js:62:62)
04/22/2024
07:51:27 PM
    at RouterResponseController.apply (/usr/src/app/node_modules/@nestjs/core/router/router-response-controller.js:15:36)
04/22/2024
07:51:27 PM
    at /usr/src/app/node_modules/@nestjs/core/router/router-execution-context.js:176:48
04/22/2024
07:51:27 PM
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
04/22/2024
07:51:27 PM
    at async /usr/src/app/node_modules/@nestjs/core/router/router-execution-context.js:47:13
04/22/2024
07:51:27 PM
    at async /usr/src/app/node_modules/@nestjs/core/router/router-proxy.js:9:17

Additional information

No response

Originally created by @Dankni95 on GitHub (May 3, 2024). ### The bug `` api/asset?skip=10000&take=10000&updatedBefore=2024-05-03T07%3A53%3A04.610024Z&userId=xxxx `` Crashes my server, if i run api call with take 5000 my server does not crash `api/asset?skip=10000&take=5000&updatedBefore=2024-05-03T07%3A53%3A04.610024Z&userId=xxxx` It seems to me like JSON.stringify is running out of memory when stringifying too many objects. More info from other places i have posted this issue: Im getting this error that crashes immich_server when building the timeline. ``` 04/23/2024 11:06:53 PM <--- Last few GCs ---> 04/23/2024 11:06:53 PM 04/23/2024 11:06:53 PM [6:0x5d52e330000] 917559 ms: Scavenge (reduce) 2044.8 (2081.5) -> 2044.1 (2081.8) MB, 7.28 / 0.00 ms (average mu = 0.338, current mu = 0.325) allocation failure; 04/23/2024 11:06:53 PM [6:0x5d52e330000] 917618 ms: Scavenge (reduce) 2044.9 (2081.8) -> 2044.2 (2081.8) MB, 5.81 / 0.00 ms (average mu = 0.338, current mu = 0.325) allocation failure; 04/23/2024 11:06:53 PM [6:0x5d52e330000] 917681 ms: Scavenge (reduce) 2045.0 (2081.8) -> 2044.4 (2082.0) MB, 4.54 / 0.00 ms (average mu = 0.338, current mu = 0.325) allocation failure; 04/23/2024 11:06:53 PM 04/23/2024 11:06:53 PM 04/23/2024 11:06:53 PM <--- JS stacktrace ---> 04/23/2024 11:06:53 PM 04/23/2024 11:06:53 PM FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory 04/23/2024 11:06:53 PM ----- Native stack trace ----- 04/23/2024 11:06:53 PM 04/23/2024 11:06:53 PM 1: 0xb84bd6 node::OOMErrorHandler(char const*, v8::OOMDetails const&) [immich_server] 04/23/2024 11:06:53 PM 2: 0xefeb90 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [immich_server] 04/23/2024 11:06:53 PM 3: 0xefee77 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [immich_server] 04/23/2024 11:06:53 PM 4: 0x1110885 [immich_server] 04/23/2024 11:06:53 PM 5: 0x1110e14 v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [immich_server] 04/23/2024 11:06:53 PM 6: 0x1127d04 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::internal::GarbageCollectionReason, char const*) [immich_server] 04/23/2024 11:06:53 PM 7: 0x112851c v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [immich_server] 04/23/2024 11:06:53 PM 8: 0x112a67a v8::internal::Heap::HandleGCRequest() [immich_server] 04/23/2024 11:06:53 PM 9: 0x1095ce7 v8::internal::StackGuard::HandleInterrupts() [immich_server] 04/23/2024 11:06:53 PM 10: 0x1537542 v8::internal::Runtime_StackGuardWithGap(int, unsigned long*, v8::internal::Isolate*) [immich_server] 04/23/2024 11:06:53 PM 11: 0x7fc429e99ef6 ``` Server crashes before reaching 4.3 gb of ram, when i added```- NODE_OPTIONS="--max-old-space-size=24000"``` it now reaches 8gb on my 64gb system. With the env variable i got this error: ``` Nest] 7 - 04/22/2024, 5:51:27 PM ERROR [ExceptionsHandler] Invalid string length 04/22/2024 07:51:27 PM RangeError: Invalid string length 04/22/2024 07:51:27 PM at JSON.stringify (<anonymous>) 04/22/2024 07:51:27 PM at stringify (/usr/src/app/node_modules/express/lib/response.js:1159:12) 04/22/2024 07:51:27 PM at ServerResponse.json (/usr/src/app/node_modules/express/lib/response.js:272:14) 04/22/2024 07:51:27 PM at ExpressAdapter.reply (/usr/src/app/node_modules/@nestjs/platform-express/adapters/express-adapter.js:62:62) 04/22/2024 07:51:27 PM at RouterResponseController.apply (/usr/src/app/node_modules/@nestjs/core/router/router-response-controller.js:15:36) 04/22/2024 07:51:27 PM at /usr/src/app/node_modules/@nestjs/core/router/router-execution-context.js:176:48 04/22/2024 07:51:27 PM at process.processTicksAndRejections (node:internal/process/task_queues:95:5) 04/22/2024 07:51:27 PM at async /usr/src/app/node_modules/@nestjs/core/router/router-execution-context.js:47:13 04/22/2024 07:51:27 PM at async /usr/src/app/node_modules/@nestjs/core/router/router-proxy.js:9:17 ``` This is only for 18k photos for this user, total 30k, 64gb allocated. Help much appreciated. ### The OS that Immich Server is running on Ubuntu 22.10 ### Version of Immich Server latest ### Version of Immich Mobile App latest ### Platform with the issue - [X] Server - [X] Web - [X] Mobile ### Your docker-compose.yml content ```YAML Can post if really needed ``` ### Your .env content ```Shell no env ``` ### Reproduction steps ```bash 1. upload 15k assets on web 2. try to build timeline on ios/android 3. or call api `api/asset?skip=10000&take=10000&updatedBefore=2024-05-03T07%3A53%3A04.610024Z&userId=xxxx` ... ``` ### Relevant log output ```shell Nest] 7 - 04/22/2024, 5:51:27 PM ERROR [ExceptionsHandler] Invalid string length 04/22/2024 07:51:27 PM RangeError: Invalid string length 04/22/2024 07:51:27 PM at JSON.stringify (<anonymous>) 04/22/2024 07:51:27 PM at stringify (/usr/src/app/node_modules/express/lib/response.js:1159:12) 04/22/2024 07:51:27 PM at ServerResponse.json (/usr/src/app/node_modules/express/lib/response.js:272:14) 04/22/2024 07:51:27 PM at ExpressAdapter.reply (/usr/src/app/node_modules/@nestjs/platform-express/adapters/express-adapter.js:62:62) 04/22/2024 07:51:27 PM at RouterResponseController.apply (/usr/src/app/node_modules/@nestjs/core/router/router-response-controller.js:15:36) 04/22/2024 07:51:27 PM at /usr/src/app/node_modules/@nestjs/core/router/router-execution-context.js:176:48 04/22/2024 07:51:27 PM at process.processTicksAndRejections (node:internal/process/task_queues:95:5) 04/22/2024 07:51:27 PM at async /usr/src/app/node_modules/@nestjs/core/router/router-execution-context.js:47:13 04/22/2024 07:51:27 PM at async /usr/src/app/node_modules/@nestjs/core/router/router-proxy.js:9:17 ``` ### Additional information _No response_
Author
Owner

@bo0tzz commented on GitHub (May 3, 2024):

I don't know if there's anything we can do to make take=10000 possible, I'm inclined to just say "don't do that" :P Maybe we should limit that parameter to an amount that won't crash things though.

@bo0tzz commented on GitHub (May 3, 2024): I don't know if there's anything we can do to make `take=10000` possible, I'm inclined to just say "don't do that" :P Maybe we should limit that parameter to an amount that won't crash things though.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: immich-app/immich#3052