#23987·harbor

jobservice crashes when a scan job's stats key is missing: getStatus asserts nil in a goroutine without recover

Author: villcaboCreated Sep 23, 2026Updated Sep 28, 2026
Labelsarea/job-services

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 +0x67b

Root cause

Two things combine.

getStatus asserts the HMGET reply without checking it:

go
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 the recover() in runner/redis.go:161 catches it and only that job fails;
  • in each report routine that scan.(*Job).Run starts with go func (job.go:225), which checks shouldStop() every few seconds while waiting for the report. That goroutine has no recover(), and the runner's one does not cover it, because a recover only 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:

  1. Status() on a tracker whose job stats key does not exist, or exists without a status field: panics with the message above on main.
  2. scan.(*Job).Run with a context whose OPCommand panics inside the report routine: crashes the test binary on main.

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-photon of v2.15.2. Before upgrading, on v2.15.1 with redis-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 configuration until core answers on /api/v2.0/internalconfig. That one is not what this issue is about.
  • The existing TestJob in src/pkg/scan/job_test.go passes the mime types as []string, which extractMimeTypes reads as zero mime types, so no report routine starts and this path had no coverage.