repo-updater: Panic when lazily syncing package repositories
Created by: efritz
Repo-updater panics on updates to NPM packages. This is because we're passing a zero-value repository id to Scheduler.UpdateOnce, which is created (in my local traces) by the NPM packages repo construction.
It appears that all implementations of RepoGetter do not set an ID on this record (for obvious reasons).
I'm able to locally reproduce a panic similar to the following by running a r:deps(...)
search on any Javascript repository (if dep search is enabled and an npm extsvc is on the local instance). I clear my local state by truncating lsif_dependency_repos
and running update repo set deleted_at = now() where name like 'npm/%;
to delete all extsvc repos so they'll re-sync.
[enterprise-repo-updater] goroutine 635 [running]:
[enterprise-repo-updater] runtime/debug.Stack()
[enterprise-repo-updater] /opt/homebrew/Cellar/go/1.17.6/libexec/src/runtime/debug/stack.go:24 +0x88
[enterprise-repo-updater] runtime/debug.PrintStack()
[enterprise-repo-updater] /opt/homebrew/Cellar/go/1.17.6/libexec/src/runtime/debug/stack.go:16 +0x20
[enterprise-repo-updater] github.com/sourcegraph/sourcegraph/internal/sentry.Recoverer.func1.1({0x102fde7b0, 0x140018f61c0})
[enterprise-repo-updater] /Users/efritz/dev/sourcegraph/sourcegraph/internal/sentry/sentry.go:130 +0x1bc
[enterprise-repo-updater] panic({0x102be7580, 0x102f8e430})
[enterprise-repo-updater] /opt/homebrew/Cellar/go/1.17.6/libexec/src/runtime/panic.go:1038 +0x21c
[enterprise-repo-updater] github.com/sourcegraph/sourcegraph/internal/repos.(*updateQueue).enqueue(0x1400192f680, {0x0, {0x14001950aa0, 0xc}}, 0x1)
[enterprise-repo-updater] /Users/efritz/dev/sourcegraph/sourcegraph/internal/repos/scheduler.go:529 +0x2c4
[enterprise-repo-updater] github.com/sourcegraph/sourcegraph/internal/repos.(*UpdateScheduler).UpdateOnce(0x140019763d0, 0x0, {0x14001950aa0, 0xc})
[enterprise-repo-updater] /Users/efritz/dev/sourcegraph/sourcegraph/internal/repos/scheduler.go:385 +0x68
[enterprise-repo-updater] github.com/sourcegraph/sourcegraph/cmd/repo-updater/repoupdater.(*Server).repoLookup(0x14001974b60, {0x102ff50b0, 0x1400247cb70}, {{0x140003b8f60, 0xc}, 0x1})
[enterprise-repo-updater] /Users/efritz/dev/sourcegraph/sourcegraph/cmd/repo-updater/repoupdater/server.go:330 +0x21c
[enterprise-repo-updater] github.com/sourcegraph/sourcegraph/cmd/repo-updater/repoupdater.(*Server).handleRepoLookup(0x14001974b60, {0x102fd3920, 0x14002177f80}, 0x1400113b000)
[enterprise-repo-updater] /Users/efritz/dev/sourcegraph/sourcegraph/cmd/repo-updater/repoupdater/server.go:117 +0x138
[enterprise-repo-updater] net/http.HandlerFunc.ServeHTTP(0x1400214cac0, {0x102fd3920, 0x14002177f80}, 0x1400113b000)
[enterprise-repo-updater] /opt/homebrew/Cellar/go/1.17.6/libexec/src/net/http/server.go:2047 +0x40
[enterprise-repo-updater] net/http.(*ServeMux).ServeHTTP(0x14002116fc0, {0x102fd3920, 0x14002177f80}, 0x1400113b000)
[enterprise-repo-updater] /opt/homebrew/Cellar/go/1.17.6/libexec/src/net/http/server.go:2425 +0x18c
[enterprise-repo-updater] github.com/sourcegraph/sourcegraph/cmd/repo-updater/repoupdater.(*observedHandler).ServeHTTP(0x14002162840, {0x102fdfa70, 0x14001cbda40}, 0x1400113b000)
[enterprise-repo-updater] /Users/efritz/dev/sourcegraph/sourcegraph/cmd/repo-updater/repoupdater/observability.go:111 +0x104
[enterprise-repo-updater] github.com/opentracing-contrib/go-stdlib/nethttp.MiddlewareFunc.func5({0x102fdfa70, 0x14001cbda40}, 0x1400113b000)
[enterprise-repo-updater] /Users/efritz/go/pkg/mod/github.com/opentracing-contrib/[email protected]/nethttp/server.go:119 +0x6a8
[enterprise-repo-updater] net/http.HandlerFunc.ServeHTTP(0x14002117000, {0x102fdfa70, 0x14001cbda40}, 0x1400113b000)
[enterprise-repo-updater] /opt/homebrew/Cellar/go/1.17.6/libexec/src/net/http/server.go:2047 +0x40
[enterprise-repo-updater] github.com/sourcegraph/sourcegraph/internal/trace/ot.MiddlewareWithTracer.func2({0x102fdfa70, 0x14001cbda40}, 0x1400113af00)
[enterprise-repo-updater] /Users/efritz/dev/sourcegraph/sourcegraph/internal/trace/ot/ot.go:70 +0x3b4
[enterprise-repo-updater] net/http.HandlerFunc.ServeHTTP(0x14001a38e10, {0x102fdfa70, 0x14001cbda40}, 0x1400113af00)
[enterprise-repo-updater] /opt/homebrew/Cellar/go/1.17.6/libexec/src/net/http/server.go:2047 +0x40
[enterprise-repo-updater] github.com/sourcegraph/sourcegraph/cmd/repo-updater/shared.Main.func4.1({0x102fdfa70, 0x14001cbda40}, 0x1400113ae00)
[enterprise-repo-updater] /Users/efritz/dev/sourcegraph/sourcegraph/cmd/repo-updater/shared/main.go:236 +0x2d0
[enterprise-repo-updater] net/http.HandlerFunc.ServeHTTP(0x14001a38e40, {0x102fdfa70, 0x14001cbda40}, 0x1400113ae00)
[enterprise-repo-updater] /opt/homebrew/Cellar/go/1.17.6/libexec/src/net/http/server.go:2047 +0x40
[enterprise-repo-updater] github.com/felixge/httpsnoop.CaptureMetrics.func1({0x102fdfa70, 0x14001cbda40})
[enterprise-repo-updater] /Users/efritz/go/pkg/mod/github.com/felixge/[email protected]/capture_metrics.go:29 +0x48
[enterprise-repo-updater] github.com/felixge/httpsnoop.CaptureMetricsFn({0x102fde7b0, 0x140018f61c0}, 0x14001240bb8)
[enterprise-repo-updater] /Users/efritz/go/pkg/mod/github.com/felixge/[email protected]/capture_metrics.go:76 +0x1f0
[enterprise-repo-updater] github.com/felixge/httpsnoop.CaptureMetrics({0x102fb6a40, 0x14001a38e40}, {0x102fde7b0, 0x140018f61c0}, 0x1400113ae00)
[enterprise-repo-updater] /Users/efritz/go/pkg/mod/github.com/felixge/[email protected]/capture_metrics.go:28 +0x68
[enterprise-repo-updater] github.com/sourcegraph/sourcegraph/internal/trace.HTTPMiddleware.func1({0x102fde7b0, 0x140018f61c0}, 0x1400113ad00)
[enterprise-repo-updater] /Users/efritz/dev/sourcegraph/sourcegraph/internal/trace/httptrace.go:178 +0xa68
[enterprise-repo-updater] net/http.HandlerFunc.ServeHTTP(0x140021628a0, {0x102fde7b0, 0x140018f61c0}, 0x1400113ad00)
[enterprise-repo-updater] /opt/homebrew/Cellar/go/1.17.6/libexec/src/net/http/server.go:2047 +0x40
[enterprise-repo-updater] github.com/sourcegraph/sourcegraph/internal/sentry.Recoverer.func1({0x102fde7b0, 0x140018f61c0}, 0x1400113ad00)
[enterprise-repo-updater] /Users/efritz/dev/sourcegraph/sourcegraph/internal/sentry/sentry.go:136 +0x74
[enterprise-repo-updater] net/http.HandlerFunc.ServeHTTP(0x14001a38e58, {0x102fde7b0, 0x140018f61c0}, 0x1400113ad00)
[enterprise-repo-updater] /opt/homebrew/Cellar/go/1.17.6/libexec/src/net/http/server.go:2047 +0x40
[enterprise-repo-updater] github.com/opentracing-contrib/go-stdlib/nethttp.MiddlewareFunc.func5({0x102fde7b0, 0x140018f61c0}, 0x1400113ad00)
[enterprise-repo-updater] /Users/efritz/go/pkg/mod/github.com/opentracing-contrib/[email protected]/nethttp/server.go:119 +0x6a8
[enterprise-repo-updater] net/http.HandlerFunc.ServeHTTP(0x14002117080, {0x102fde7b0, 0x140018f61c0}, 0x1400113ad00)
[enterprise-repo-updater] /opt/homebrew/Cellar/go/1.17.6/libexec/src/net/http/server.go:2047 +0x40
[enterprise-repo-updater] github.com/sourcegraph/sourcegraph/internal/trace/ot.MiddlewareWithTracer.func2({0x102fde7b0, 0x140018f61c0}, 0x1400113ac00)
[enterprise-repo-updater] /Users/efritz/dev/sourcegraph/sourcegraph/internal/trace/ot/ot.go:70 +0x3b4
[enterprise-repo-updater] net/http.HandlerFunc.ServeHTTP(0x14001a38e88, {0x102fde7b0, 0x140018f61c0}, 0x1400113ac00)
[enterprise-repo-updater] /opt/homebrew/Cellar/go/1.17.6/libexec/src/net/http/server.go:2047 +0x40
[enterprise-repo-updater] net/http.serverHandler.ServeHTTP({0x140018f6c40}, {0x102fde7b0, 0x140018f61c0}, 0x1400113ac00)
[enterprise-repo-updater] /opt/homebrew/Cellar/go/1.17.6/libexec/src/net/http/server.go:2879 +0x444
[enterprise-repo-updater] net/http.(*conn).serve(0x14001274320, {0x102ff50b0, 0x14001e9a840})
[enterprise-repo-updater] /opt/homebrew/Cellar/go/1.17.6/libexec/src/net/http/server.go:1930 +0xb6c
[enterprise-repo-updater] created by net/http.(*Server).Serve
[enterprise-repo-updater] /opt/homebrew/Cellar/go/1.17.6/libexec/src/net/http/server.go:3034 +0x4b8