mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2026-04-27 21:00:40 +00:00
core: auto-size NODE_OPTIONS heap (#13960)
* feat(nodejs): auto-size NODE_OPTIONS heap and apply in Termix updates - setup_nodejs now sets NODE_OPTIONS only when not already set - Heap size is auto-derived from NODE_MAX_OLD_SPACE_SIZE, var_ram, or MemTotal - Auto heap is clamped to 1024..4096 MB to avoid too-small or too-large defaults - Termix update path now calls setup_nodejs before frontend/backend builds so Node heap defaults are applied consistently during updates * feat(error-handler): add actionable Node.js heap OOM guidance Detect probable Node.js heap out-of-memory failures from log patterns and common build exit codes, then print targeted remediation hints instead of only a generic SIGABRT/SIGKILL message. - Detect OOM patterns in last log lines (Reached heap limit, JS heap OOM) - Treat node build contexts with exit 134/137/243 as likely heap issues - Suggest computed --max-old-space-size based on NODE_OPTIONS, var_ram, or MemTotal (clamped to 1024..4096 MB) - Recommend calling setup_nodejs before build steps so defaults apply * refactor(node-heap): raise auto cap to 12GB and simplify OOM hint - Increase setup_nodejs auto heap clamp from 4GB to 12GB for heavy frontend builds - Keep lower bound at 1GB and preserve user override precedence - Simplify error_handler Node OOM output to a single concise hint - Align error_handler heap suggestion clamp to 12GB
This commit is contained in:
committed by
GitHub
parent
c3c544d5a4
commit
fdab25b098
+31
-1
@@ -6423,7 +6423,37 @@ function setup_nodejs() {
|
||||
msg_ok "Setup Node.js $NODE_VERSION"
|
||||
fi
|
||||
|
||||
export NODE_OPTIONS="--max-old-space-size=4096"
|
||||
# Set a safe default heap limit for Node.js builds if not explicitly provided.
|
||||
# Priority:
|
||||
# 1) NODE_OPTIONS (caller/user override)
|
||||
# 2) NODE_MAX_OLD_SPACE_SIZE (explicit MB override)
|
||||
# 3) var_ram (LXC memory setting, MB)
|
||||
# 4) /proc/meminfo (runtime memory detection)
|
||||
# Auto value is clamped to 1024..12288 MB.
|
||||
if [[ -z "${NODE_OPTIONS:-}" ]]; then
|
||||
local node_heap_mb=""
|
||||
|
||||
if [[ -n "${NODE_MAX_OLD_SPACE_SIZE:-}" ]] && [[ "${NODE_MAX_OLD_SPACE_SIZE}" =~ ^[0-9]+$ ]]; then
|
||||
node_heap_mb="${NODE_MAX_OLD_SPACE_SIZE}"
|
||||
elif [[ -n "${var_ram:-}" ]] && [[ "${var_ram}" =~ ^[0-9]+$ ]]; then
|
||||
node_heap_mb=$((var_ram * 75 / 100))
|
||||
else
|
||||
local total_mem_kb=""
|
||||
total_mem_kb=$(awk '/^MemTotal:/ {print $2; exit}' /proc/meminfo 2>/dev/null || echo "")
|
||||
if [[ "$total_mem_kb" =~ ^[0-9]+$ ]]; then
|
||||
local total_mem_mb=$((total_mem_kb / 1024))
|
||||
node_heap_mb=$((total_mem_mb * 75 / 100))
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z "$node_heap_mb" ]] || ((node_heap_mb < 1024)); then
|
||||
node_heap_mb=1024
|
||||
elif ((node_heap_mb > 12288)); then
|
||||
node_heap_mb=12288
|
||||
fi
|
||||
|
||||
export NODE_OPTIONS="--max-old-space-size=${node_heap_mb}"
|
||||
fi
|
||||
|
||||
# Ensure valid working directory for npm (avoids uv_cwd error)
|
||||
if [[ ! -d /opt ]]; then
|
||||
|
||||
Reference in New Issue
Block a user