Skip to content

fix: handle null from shell_exec('nproc') in Utils::cpuCount() (#150)#177

Merged
s2x merged 1 commit intomasterfrom
fix/150-cpucount-null-safety
May 2, 2026
Merged

fix: handle null from shell_exec('nproc') in Utils::cpuCount() (#150)#177
s2x merged 1 commit intomasterfrom
fix/150-cpucount-null-safety

Conversation

@s2x
Copy link
Copy Markdown
Collaborator

@s2x s2x commented May 2, 2026

Problem

Utils::cpuCount() returns 0 when shell_exec('nproc') returns null (e.g., on systems without coreutils/nproc). Downstream, ServerWorker uses Utils::cpuCount() * 2 for worker count → zero workers spawned.

Root cause

(int) shell_exec('nproc') — when shell_exec is available but the nproc command is not, shell_exec returns null, and (int) null === 0. No fallback existed.

Additionally, shell output (e.g., "8\n") was not trimmed — relied on fragile implicit casting.

Fix

  • Check shell_exec return value explicitly for null → return 1
  • Add trim() on shell output before casting
  • Return 1 as safe fallback when parsed count is ≤ 0

Testing

shell_exec('nproc') returns null when nproc is not available on the
system (e.g., minimal containers without coreutils). Casting null to
int yields 0, causing cpuCount() to return 0 — downstream this means
zero workers spawned in ServerWorker.

Fix: explicitly check for null, add trim() for shell output, and
return 1 as safe fallback.
@s2x s2x force-pushed the fix/150-cpucount-null-safety branch from 133fa26 to 591fa68 Compare May 2, 2026 21:05
@s2x s2x merged commit 6381f6a into master May 2, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant