Skip to content

Commit 86c1a1c

Browse files
committed
fix(build): raise file limit for native gateway builds
Native gateway builds exhaust the default open-file soft limit. Raise the soft limit to the hard limit (capped) in the shared build environment and apply it from the gateway task scripts. Explicitly read the current soft limit and only raise it when needed. Signed-off-by: Jim Meyer <jimeyer@nvidia.com>
1 parent be7af99 commit 86c1a1c

5 files changed

Lines changed: 25 additions & 37 deletions

File tree

‎tasks/gateway.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
["build:gateway"]
77
description = "Build the standalone openshell-gateway binary"
8-
run = "cargo build -p openshell-gateway --bin openshell-gateway"
8+
run = "bash -c 'source tasks/scripts/build-env.sh && ensure_build_nofile_limit && cargo build -p openshell-gateway --bin openshell-gateway'"
99
hide = true
1010

1111
["gateway"]

‎tasks/scripts/build-env.sh‎

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,19 @@
33
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
44
# SPDX-License-Identifier: Apache-2.0
55

6-
# Shared build-environment helpers for host-side cross-compilation.
6+
# Shared build-environment helpers for host-side Rust builds.
77
#
88
# Source this file (do not execute it) and call the helpers before invoking
9-
# cargo-zigbuild on the host.
9+
# Cargo on the host.
1010

1111
# ensure_build_nofile_limit raises the per-process open-file limit before a
12-
# host cargo-zigbuild cross-compile. The static *-unknown-linux-musl link opens
13-
# hundreds of .rlib files simultaneously, which exceeds macOS's default soft
14-
# limit of 256 and fails with ProcessFdQuotaExceeded. The raised limit
15-
# propagates to the cargo/zig children the caller spawns.
12+
# host Rust build. Sccache and static *-unknown-linux-musl links can each open
13+
# hundreds of files simultaneously, exceeding macOS's default soft limit of
14+
# 256. The raised limit propagates to the Cargo children the caller spawns.
1615
#
1716
# The limit is read from OPENSHELL_BUILD_NOFILE_LIMIT (default 8192), honoring
18-
# the legacy OPENSHELL_VM_BUILD_NOFILE_LIMIT for back-compat. This is a no-op on
19-
# Linux and when cargo-zigbuild is not installed (native builds, CI Linux
20-
# runners), so it must be safe to call unconditionally.
17+
# the legacy OPENSHELL_VM_BUILD_NOFILE_LIMIT for back-compat. This is a no-op
18+
# on Linux, so it must be safe to call unconditionally.
2119
ensure_build_nofile_limit() {
2220
local desired="${OPENSHELL_BUILD_NOFILE_LIMIT:-${OPENSHELL_VM_BUILD_NOFILE_LIMIT:-8192}}"
2321
local minimum=1024
@@ -26,9 +24,7 @@ ensure_build_nofile_limit() {
2624
local target=""
2725

2826
[ "$(uname -s)" = "Darwin" ] || return 0
29-
command -v cargo-zigbuild >/dev/null 2>&1 || return 0
30-
31-
current="$(ulimit -n 2>/dev/null || echo "")"
27+
current="$(ulimit -Sn 2>/dev/null || echo "")"
3228
case "${current}" in
3329
''|*[!0-9]*)
3430
return 0
@@ -53,24 +49,24 @@ ensure_build_nofile_limit() {
5349
;;
5450
esac
5551

56-
if [ "${target}" -gt "${current}" ] && ulimit -n "${target}" 2>/dev/null; then
57-
echo "==> Raised open file limit for cargo-zigbuild: ${current} -> $(ulimit -n)"
52+
if [ "${target}" -gt "${current}" ] && ulimit -Sn "${target}" 2>/dev/null; then
53+
echo "==> Raised open file limit for host Cargo build: ${current} -> $(ulimit -Sn)"
5854
fi
5955

60-
current="$(ulimit -n 2>/dev/null || echo "${current}")"
56+
current="$(ulimit -Sn 2>/dev/null || echo "${current}")"
6157
case "${current}" in
6258
''|*[!0-9]*)
6359
return 0
6460
;;
6561
esac
6662

6763
if [ "${current}" -lt "${desired}" ]; then
68-
echo "WARNING: Open file limit is ${current}; cargo-zigbuild is more reliable at ${desired}+ on macOS."
64+
echo "WARNING: Open file limit is ${current}; host Cargo builds are more reliable at ${desired}+ on macOS."
6965
fi
7066

7167
if [ "${current}" -lt "${minimum}" ]; then
72-
echo "ERROR: Open file limit (${current}) is too low for cargo-zigbuild on macOS." >&2
73-
echo " Run: ulimit -n ${desired}" >&2
68+
echo "ERROR: Open file limit (${current}) is too low for host Cargo builds on macOS." >&2
69+
echo " Run: ulimit -Sn ${desired}" >&2
7470
echo " Then re-run this script." >&2
7571
exit 1
7672
fi

‎tasks/scripts/gateway-docker.sh‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
3030
source "${ROOT}/tasks/scripts/gateway-toml.sh"
3131
# shellcheck source=tasks/scripts/gateway-pull-policy.sh
3232
source "${ROOT}/tasks/scripts/gateway-pull-policy.sh"
33+
# shellcheck source=tasks/scripts/build-env.sh
34+
source "${ROOT}/tasks/scripts/build-env.sh"
35+
ensure_build_nofile_limit
3336
PORT="${OPENSHELL_SERVER_PORT:-18080}"
3437
GATEWAY_NAME="${OPENSHELL_DOCKER_GATEWAY_NAME:-docker-dev}"
3538
STATE_DIR="${OPENSHELL_DOCKER_GATEWAY_STATE_DIR:-${ROOT}/.cache/gateway-docker}"

‎tasks/scripts/gateway-vm.sh‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ set -euo pipefail
3535
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
3636
# shellcheck source=tasks/scripts/gateway-toml.sh
3737
source "${ROOT}/tasks/scripts/gateway-toml.sh"
38+
# shellcheck source=tasks/scripts/build-env.sh
39+
source "${ROOT}/tasks/scripts/build-env.sh"
40+
ensure_build_nofile_limit
3841
PORT="${OPENSHELL_SERVER_PORT:-18081}"
3942
GATEWAY_NAME="${OPENSHELL_VM_GATEWAY_NAME:-vm-dev}"
4043
STATE_DIR="${OPENSHELL_VM_GATEWAY_STATE_DIR:-${ROOT}/.cache/gateway-vm}"

‎tasks/scripts/test-build-env.sh‎

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,14 @@ if [ "${os}" != "Darwin" ]; then
3838
exit 0
3939
fi
4040

41-
# Darwin below.
42-
if ! command -v cargo-zigbuild >/dev/null 2>&1; then
43-
# Without cargo-zigbuild the helper must be a no-op even on macOS.
44-
(
45-
ulimit -Sn 256 2>/dev/null || true
46-
before="$(ulimit -n)"
47-
ensure_build_nofile_limit >/dev/null
48-
after="$(ulimit -n)"
49-
[ "${before}" = "${after}" ] || fail "limit changed on macOS without cargo-zigbuild (${before} -> ${after})"
50-
)
51-
pass "no-op on macOS without cargo-zigbuild"
52-
echo "All build-env tests passed."
53-
exit 0
54-
fi
55-
56-
# Darwin + cargo-zigbuild: the helper should raise a low soft limit.
41+
# Darwin native Cargo builds need the same protection even when
42+
# cargo-zigbuild is unavailable.
5743
(
5844
if ! ulimit -Sn 256 2>/dev/null; then
5945
echo "SKIP: unable to lower soft limit to 256 for test"
6046
exit 0
6147
fi
62-
ensure_build_nofile_limit >/dev/null
48+
PATH="/usr/bin:/bin" ensure_build_nofile_limit >/dev/null
6349
after="$(ulimit -n)"
6450
hard="$(ulimit -Hn 2>/dev/null || echo unlimited)"
6551
case "${hard}" in
@@ -76,7 +62,7 @@ fi
7662
;;
7763
esac
7864
)
79-
pass "raises low soft limit on macOS with cargo-zigbuild"
65+
pass "raises low soft limit for native Cargo builds on macOS"
8066

8167
# Idempotent: when the current limit already meets the desired value, the helper
8268
# leaves it unchanged (drive this via the env override so it holds regardless of

0 commit comments

Comments
 (0)