fix(scheduler): put_resvals treats resource idx 0 as invalid → SEGV

put_resvals (resource.c) used `idxs[i] <= 0` to skip "invalid" resource
indexes, but index 0 IS valid — it's the first resource in the table
(e.g. "slots"). For idx 0 the val was never allocated (xvals[i] stayed
NULL) and the write loop then SEGV'd. bug-1495.

Fix: skip only negative indexes (`idxs[i] < 0`), and NULL-guard the
write loop defensively.

Verified end-to-end: a locally-built scheduler now connects to the t1
controller and dispatches all 5 test jobs to node t1 (exec_hosts
populated, jobs run and exit). This was the final blocker for job
scheduling (bug-1494: all jobs PEND).

Also: add the t1 host definition to hosts.yaml (worker join was rejected
with -EINVAL because no matching hostconfig existed for hostname "t1").

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
lei.chen 2026-08-03 06:53:14 +00:00
parent 62dee0edc1
commit 07ab05671d
4 changed files with 57 additions and 4 deletions

View file

@ -35,6 +35,15 @@ hosts:
model: "x86_64-linux-gnu"
max_slot: 128
# t1: primary test node (172.31.1.30). Must match the hostname the worker
# reports via gethostname(); without a matching hostconfig, the worker's
# join is rejected with -EINVAL (find_matched_hostconfig fails) and no
# compute node ever registers, so every job stays PEND (bug-1494).
- hostname: t1
type: "x86_64-linux-gnu"
model: "x86_64-linux-gnu"
max_slot: 8
hostgroups:
- groupname: hg1

View file

@ -69,7 +69,10 @@ int put_resvals(zarray_t* array, int nres, int* idxs, float* vals)
}
for (i = 0; i < nres; i++) {
if (idxs[i] <= 0) {
/* A resource index of 0 is VALID (the first resource — e.g. "slots").
* Only negative indexes are invalid. bug-1495: the old `<= 0` skipped
* idx 0, leaving xvals[i] NULL and then SEGV on the write below. */
if (idxs[i] < 0) {
continue;
}
@ -87,6 +90,9 @@ int put_resvals(zarray_t* array, int nres, int* idxs, float* vals)
}
for (i = 0; i < nres; i++) {
if (xvals[i] == NULL) {
continue; /* defensive: idx<0 skipped, or allocation failed above */
}
xvals[i]->u.fvalue = vals[i];
}