jobservice crashes when a scan job's stats key is missing: getStatus asserts nil in a goroutine without recover
Expected behavior and actual behavior:
Expected: when a job's stats disappear from Redis while the job is still running, the job fails or keeps polling, and jobservice stays up.
Actual: jobservice panics and the whole process exits. restart: always brings it back, but every job in flight at that moment dies with it: scans, replication, GC, retention, webhooks.
panic: interface conversion: interface {} is nil, not []uint8
goroutine 170 [running]:
github.com/goharbor/harbor/src/jobservice/job.getStatus(...)
/harbor/src/jobservice/job/tracker.go:619 +0x16b
github.com/goharbor/harbor/src/jobservice/job.(*basicTracker).Status(...)
/harbor/src/jobservice/job/tracker.go:193 +0xa9
github.com/goharbor/harbor/src/jobservice/job/impl.(*Context).OPCommand(...)
/harbor/src/jobservice/job/impl/context.go:162 +0x1c
github.com/goharbor/harbor/src/pkg/scan.(*Job).Run.func1()
/harbor/src/pkg/scan/job.go:151 +0x32
github.com/goharbor/harbor/src/pkg/scan.(*Job).Run.func2(0x0, {...})
/harbor/src/pkg/scan/job.go:238 +0x330
created by github.com/goharbor/harbor/src/pkg/scan.(*Job).Run in goroutine 106
/harbor/src/pkg/scan/job.go:225 +0x67bRoot cause
Two things combine.
getStatus asserts the HMGET reply without checking it:
values, err := rds.HmGet(conn, key, "status")
...
if len(values) == 1 {
st := Status(values[0].([]byte))HMGET for one field always returns a one-element list. When the key or the field is missing, that element is nil, not an error, so len(values) == 1 holds and the assertion panics.
Where that panic lands decides what it costs. The scan job's shouldStop() calls ctx.OPCommand(), which calls tracker.Status(). It runs in two places:
- in the job goroutine (
job.go:174), where therecover()inrunner/redis.go:161catches it and only that job fails; - in each report routine that
scan.(*Job).Runstarts withgo func(job.go:225), which checksshouldStop()every few seconds while waiting for the report. That goroutine has norecover(), and the runner's one does not cover it, because arecoveronly guards its own goroutine. The process dies.
In three hours of jobservice logs we saw both: two panics caught on the protected path, and two that crashed the process from the report routine.
Steps to reproduce the problem:
It depends on the job stats key being gone while a scan is still polling for its report, so it does not reproduce by clicking around. It does reproduce deterministically in a test, and the fix PR adds one for each half:
Status()on a tracker whose job stats key does not exist, or exists without astatusfield: panics with the message above onmain.scan.(*Job).Runwith a context whoseOPCommandpanics inside the report routine: crashes the test binary onmain.
What removes the key in production we have not pinned down. Candidates are the stats TTL expiring during a long scan, or Redis restarting. One of the crashes came 29 seconds after the cache container restarted.
Versions:
- harbor version: v2.15.2 (the code is identical in
main) - docker engine version: 29.7.2
- docker-compose version: 5.5.0
Additional context:
- Cache backend: the bundled
valkey-photonof v2.15.2. Before upgrading, on v2.15.1 withredis-photon, the jobservice container had accumulated 361 restarts, which fits this crash. - Most restarts at startup are a different, harmless thing: jobservice panics with
failed to load configurationuntil core answers on/api/v2.0/internalconfig. That one is not what this issue is about. - The existing
TestJobinsrc/pkg/scan/job_test.gopasses the mime types as[]string, whichextractMimeTypesreads as zero mime types, so no report routine starts and this path had no coverage.
Source: goharbor/harbor