Skip to content

actor: fix panic

Administrator requested to merge ts/fix-panics into main

Created by: tsenart

When an error occurred in the once.Do block, accessing a.user panicked. This commits fixes it. I noticed this in prod logs.

panic: runtime error: invalid memory address or nil pointer dereference

stack trace:
goroutine 1899373 [running]:
github.com/sourcegraph/sourcegraph/cmd/frontend/internal/handlerutil.HandlerWithErrorReturn.ServeHTTP.func1()
	github.com/sourcegraph/sourcegraph/cmd/frontend/internal/handlerutil/handler.go:41 +0x10d
panic({0x244c220, 0x87ebdc0})
	runtime/panic.go:1038 +0x215
github.com/sourcegraph/sourcegraph/internal/actor.(*Actor).User(0xc18fa42330, {0x6eb23e8, 0xc3788b3bc0}, {0x6e52ca0, 0xc378883d58})
	github.com/sourcegraph/sourcegraph/internal/actor/actor.go:68 +0xb7
github.com/sourcegraph/sourcegraph/internal/database.(*UserStore).GetByCurrentAuthUser(0x6eb23e8, {0x6eb23e8, 0xc3788b3bc0})
	github.com/sourcegraph/sourcegraph/internal/database/users.go:741 +0x79
github.com/sourcegraph/sourcegraph/internal/database.AuthzQueryConds({0x6eb23e8, 0xc3788b3bc0}, {0x6e7fa78, 0xc001ee05b0})
	github.com/sourcegraph/sourcegraph/internal/database/repos_perm.go:46 +0x1d4
github.com/sourcegraph/sourcegraph/internal/database.(*RepoStore).listSQL(_, {_, _}, {{0x0, 0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0, ...}, ...})
	github.com/sourcegraph/sourcegraph/internal/database/repos.go:1020 +0x22d3
github.com/sourcegraph/sourcegraph/internal/database.(*RepoStore).list(_, {_, _}, _, {{0x0, 0x0, 0x0}, {0x0, 0x0}, {0x0, ...}, ...}, ...)
	github.com/sourcegraph/sourcegraph/internal/database/repos.go:782 +0xa5
github.com/sourcegraph/sourcegraph/internal/database.(*RepoStore).listRepos(_, {_, _}, _, {{0x0, 0x0, 0x0}, {0x0, 0x0}, {0x0, ...}, ...})
	github.com/sourcegraph/sourcegraph/internal/database/repos.go:759 +0xee
github.com/sourcegraph/sourcegraph/internal/database.(*RepoStore).GetByName(0x6eb23b0, {0x6eb23e8, 0xc3788b3ad0}, {0xc32bf79b45, 0x28755a8})
	github.com/sourcegraph/sourcegraph/internal/database/repos.go:200 +0x258
github.com/sourcegraph/sourcegraph/cmd/frontend/backend.(*repos).GetByName(0x8814310, {0x6eb23b0, 0xc3753dbaa0}, {0xc32bf79b45, 0x25})
	github.com/sourcegraph/sourcegraph/cmd/frontend/backend/repos.go:75 +0x1c6
github.com/sourcegraph/sourcegraph/cmd/frontend/backend.listGoPackagesInRepoImprecise({0x6eb23b0, 0xc3753dbaa0}, {0xc32bf79b45, 0x0})
	github.com/sourcegraph/sourcegraph/cmd/frontend/backend/go_importers.go:127 +0x79
github.com/sourcegraph/sourcegraph/cmd/frontend/backend.CountGoImporters({0x6eb23e8, 0xc18f9c7bf0}, {0xc32bf79b45, 0x25})
	github.com/sourcegraph/sourcegraph/cmd/frontend/backend/go_importers.go:67 +0x20d
github.com/sourcegraph/sourcegraph/cmd/frontend/internal/app.badgeValue(0x4)
	github.com/sourcegraph/sourcegraph/cmd/frontend/internal/app/badge.go:22 +0x7b
github.com/sourcegraph/sourcegraph/cmd/frontend/internal/app.serveRepoBadge({0x6e8fa68, 0xc031c55f20}, 0xc32164fa00)
	github.com/sourcegraph/sourcegraph/cmd/frontend/internal/app/badge.go:44 +0x49
github.com/sourcegraph/sourcegraph/cmd/frontend/internal/handlerutil.HandlerWithErrorReturn.ServeHTTP({0x6a3a8b0, 0x6a3a8c0, 0xd1}, {0x6e8fa68, 0xc031c55f20}, 0xc32164fa00)
	github.com/sourcegraph/sourcegraph/cmd/frontend/internal/handlerutil/handler.go:53 +0xe3
github.com/sourcegraph/sourcegraph/internal/trace.Route.func1({0x6e8fa68, 0xc031c55f20}, 0xc32164fa00)
	github.com/sourcegraph/sourcegraph/internal/trace/httptrace.go:285 +0xe4
net/http.HandlerFunc.ServeHTTP(0xc32164f900, {0x6e8fa68, 0xc031c55f20}, 0x61d6ec31b46d6542)
	net/http/server.go:2046 +0x2f
github.com/gorilla/mux.(*Router).ServeHTTP(0xc000375740, {0x6e8fa68, 0xc031c55f20}, 0xc32164f800)
	github.com/gorilla/[email protected]/mux.go:210 +0x1cf
net/http.(*ServeMux).ServeHTTP(0x6eb2378, {0x6e8fa68, 0xc031c55f20}, 0xc32164f800)
	net/http/server.go:2424 +0x149
github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/authz.Init.func5.1({0x6e8fa68, 0xc031c55f20}, 0xc32164f800)
	github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/authz/init.go:127 +0x352
net/http.HandlerFunc.ServeHTTP(0x6e83e28, {0x6e8fa68, 0xc031c55f20}, 0x4)
	net/http/server.go:2046 +0x2f
github.com/sourcegraph/sourcegraph/internal/featureflag.Middleware.func1({0x6e8fa68, 0xc031c55f20}, 0xc32164f700)
	github.com/sourcegraph/sourcegraph/internal/featureflag/middleware.go:26 +0x334
net/http.HandlerFunc.ServeHTTP(0x26387c0, {0x6e8fa68, 0xc031c55f20}, 0x4)
	net/http/server.go:2046 +0x2f
github.com/gorilla/csrf.(*csrf).ServeHTTP(0xc00351c180, {0x6e8fa68, 0xc031c55f20}, 0x1d0)
	github.com/gorilla/[email protected]/csrf.go:301 +0x592
github.com/sourcegraph/sourcegraph/cmd/frontend/internal/handlerutil.CSRFMiddleware.func2({0x6e8fa68, 0xc031c55f20}, 0x6e21558)
	github.com/sourcegraph/sourcegraph/cmd/frontend/internal/handlerutil/middleware.go:63 +0x289
net/http.HandlerFunc.ServeHTTP(0x6eb23e8, {0x6e8fa68, 0xc031c55f20}, 0x10)
	net/http/server.go:2046 +0x2f
github.com/sourcegraph/sourcegraph/cmd/frontend/auth.glob..func2.1({0x6e8fa68, 0xc031c55f20}, 0xc32164f500)
	github.com/sourcegraph/sourcegraph/cmd/frontend/auth/non_public.go:53 +0xcc
net/http.HandlerFunc.ServeHTTP(0x6eb23e8, {0x6e8fa68, 0xc031c55f20}, 0x43)
	net/http/server.go:2046 +0x2f
github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/auth/openidconnect.handleOpenIDConnectAuth({0x6e7fa78, 0xc001ee05b0}, {0x6e8fa68, 0xc031c55f20}, 0xc32164f500, {0x6e5a7a0, 0xc0004cced0}, 0x0)
	github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/auth/openidconnect/middleware.go:89 +0x1f8
github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/auth/openidconnect.Middleware.func2.1({0x6e8fa68, 0xc031c55f20}, 0x6e21558)
	github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/auth/openidconnect/middleware.go:62 +0x45
net/http.HandlerFunc.ServeHTTP(0x6eb23e8, {0x6e8fa68, 0xc031c55f20}, 0xc00dc436b8)
	net/http/server.go:2046 +0x2f
github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/auth/saml.authHandler({0x6e7fa78, 0xc001ee05b0}, {0x6e8fa68, 0xc031c55f20}, 0xc32164f500, {0x6e5a7a0, 0xc001f2ccf0}, 0x0)
	github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/auth/saml/middleware.go:57 +0x158
github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/auth/saml.Middleware.func2.1({0x6e8fa68, 0xc031c55f20}, 0xc001e50e40)
	github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/auth/saml/middleware.go:38 +0x45
net/http.HandlerFunc.ServeHTTP(0xc1fd9160e0, {0x6e8fa68, 0xc031c55f20}, 0xc00dc437f8)
	net/http/server.go:2046 +0x2f
github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/auth/httpheader.middleware.func1.1({0x6e8fa68, 0xc031c55f20}, 0xc32164f500)
	github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/auth/httpheader/middleware.go:51 +0xb89
net/http.HandlerFunc.ServeHTTP(0x6eb23e8, {0x6e8fa68, 0xc031c55f20}, 0x6e20b94)
	net/http/server.go:2046 +0x2f
github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/auth/oauth.NewHandler.func1({0x6e8fa68, 0xc031c55f20}, 0xc32164f500)
	github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/auth/oauth/middleware.go:43 +0x1ad
net/http.HandlerFunc.ServeHTTP(0x6eb23e8, {0x6e8fa68, 0xc031c55f20}, 0x6e20b94)
	net/http/server.go:2046 +0x2f
github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/auth/oauth.NewHandler.func1({0x6e8fa68, 0xc031c55f20}, 0xc32164f500)
	github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/auth/oauth/middleware.go:43 +0x1ad
net/http.HandlerFunc.ServeHTTP(0xc32164f400, {0x6e8fa68, 0xc031c55f20}, 0x4)
	net/http/server.go:2046 +0x2f
github.com/sourcegraph/sourcegraph/cmd/frontend/internal/session.CookieMiddleware.func1({0x6e8fa68, 0xc031c55f20}, 0xc32164f400)
	github.com/sourcegraph/sourcegraph/cmd/frontend/internal/session/session.go:295 +0x314
net/http.HandlerFunc.ServeHTTP(0xc18f9c75c0, {0x6e8fa68, 0xc031c55f20}, 0x5)
	net/http/server.go:2046 +0x2f
github.com/sourcegraph/sourcegraph/cmd/frontend/internal/httpapi.AccessTokenAuthMiddleware.func1({0x6e8fa68, 0xc031c55f20}, 0xc32164f400)
	github.com/sourcegraph/sourcegraph/cmd/frontend/internal/httpapi/auth.go:113 +0xe51
net/http.HandlerFunc.ServeHTTP(0xc32164f300, {0x6e8fa68, 0xc031c55f20}, 0x1)
	net/http/server.go:2046 +0x2f
github.com/sourcegraph/sourcegraph/internal/deviceid.Middleware.func1({0x6e8fa68, 0xc031c55f20}, 0xc32164f300)
	github.com/sourcegraph/sourcegraph/internal/deviceid/middleware.go:29 +0x54e
net/http.HandlerFunc.ServeHTTP(0xad981, {0x6e8fa68, 0xc031c55f20}, 0x3f)
	net/http/server.go:2046 +0x2f
net/http.(*ServeMux).ServeHTTP(0x8, {0x6e8fa68, 0xc031c55f20}, 0xc32164f300)
	net/http/server.go:2424 +0x149
github.com/sourcegraph/sourcegraph/cmd/frontend/internal/cli/middleware.Trace.func1({0x6e8fa68, 0xc031c55f20}, 0x40ceb4)
	github.com/sourcegraph/sourcegraph/cmd/frontend/internal/cli/middleware/trace.go:27 +0x196
net/http.HandlerFunc.ServeHTTP(0x40, {0x6e8fa68, 0xc031c55f20}, 0x7fb926df5978)
	net/http/server.go:2046 +0x2f
github.com/gorilla/context.ClearHandler.func1({0x6e8fa68, 0xc031c55f20}, 0xc00dc44a10)
	github.com/gorilla/[email protected]/context.go:141 +0x73
net/http.HandlerFunc.ServeHTTP(0x234a9c0, {0x6e8fa68, 0xc031c55f20}, 0x50b3df)
	net/http/server.go:2046 +0x2f
github.com/sourcegraph/sourcegraph/cmd/frontend/internal/cli.healthCheckMiddleware.func1({0x6e8fa68, 0xc031c55f20}, 0x56)
	github.com/sourcegraph/sourcegraph/cmd/frontend/internal/cli/http.go:117 +0xb4
net/http.HandlerFunc.ServeHTTP(0x0, {0x6e8fa68, 0xc031c55f20}, 0x4)
	net/http/server.go:2046 +0x2f
github.com/sourcegraph/sourcegraph/cmd/frontend/internal/cli.secureHeadersMiddleware.func1({0x6e8fa68, 0xc031c55f20}, 0xc32164f300)
	github.com/sourcegraph/sourcegraph/cmd/frontend/internal/cli/http.go:206 +0x7bf
net/http.HandlerFunc.ServeHTTP(0xc00dc44ba0, {0x6e8fa68, 0xc031c55f20}, 0xc18f9c7770)
	net/http/server.go:2046 +0x2f
github.com/sourcegraph/sourcegraph/cmd/frontend/internal/cli/middleware.BlackHole.func1({0x6e8fa68, 0xc031c55f20}, 0xc18f9c7770)
	github.com/sourcegraph/sourcegraph/cmd/frontend/internal/cli/middleware/blackhole.go:17 +0x9d
net/http.HandlerFunc.ServeHTTP(0x266b4e0, {0x6e8fa68, 0xc031c55f20}, 0x6)
	net/http/server.go:2046 +0x2f
github.com/sourcegraph/sourcegraph/cmd/frontend/internal/cli/middleware.SourcegraphComGoGetHandler.func1({0x6e8fa68, 0xc031c55f20}, 0xc32164f300)
	github.com/sourcegraph/sourcegraph/cmd/frontend/internal/cli/middleware/goimportpath.go:49 +0xd3
net/http.HandlerFunc.ServeHTTP(0x40568a, {0x6e8fa68, 0xc031c55f20}, 0xc00dc44e40)
	net/http/server.go:2046 +0x2f
github.com/sourcegraph/sourcegraph/cmd/frontend/internal/auth.ForbidAllRequestsMiddleware.func1({0x6e8fa68, 0xc031c55f20}, 0xc00dc44e58)
	github.com/sourcegraph/sourcegraph/cmd/frontend/internal/auth/forbid_all.go:19 +0x8e
net/http.HandlerFunc.ServeHTTP(0x0, {0x6e8fa68, 0xc031c55f20}, 0xc0016c1aa0)
	net/http/server.go:2046 +0x2f
github.com/sourcegraph/sourcegraph/cmd/frontend/internal/auth.OverrideAuthMiddleware.func1({0x6e8fa68, 0xc031c55f20}, 0xc32164f300)
	github.com/sourcegraph/sourcegraph/cmd/frontend/internal/auth/override.go:83 +0xaeb
net/http.HandlerFunc.ServeHTTP(0x40d207, {0x6e8fa68, 0xc031c55f20}, 0x48b101)
	net/http/server.go:2046 +0x2f
github.com/felixge/httpsnoop.CaptureMetrics.func1({0x6e8fa68, 0xc031c55f20})
	github.com/felixge/[email protected]/capture_metrics.go:29 +0x39
github.com/felixge/httpsnoop.CaptureMetricsFn({0x6e8e388, 0xc01cab2fc0}, 0xc00dc45240)
	github.com/felixge/[email protected]/capture_metrics.go:76 +0x212
github.com/felixge/httpsnoop.CaptureMetrics({0x6e5a7a0, 0xc001fdd200}, {0x6e8e388, 0xc01cab2fc0}, 0x234a9c0)
	github.com/felixge/[email protected]/capture_metrics.go:28 +0x6b
github.com/sourcegraph/sourcegraph/internal/trace.HTTPTraceMiddleware.func1({0x6e8e388, 0xc01cab2fc0}, 0xc32164f200)
	github.com/sourcegraph/sourcegraph/internal/trace/httptrace.go:182 +0x979
net/http.HandlerFunc.ServeHTTP(0x0, {0x6e8e388, 0xc01cab2fc0}, 0x403c6c)
	net/http/server.go:2046 +0x2f
github.com/sourcegraph/sourcegraph/internal/sentry.Recoverer.func1({0x6e8e388, 0xc01cab2fc0}, 0x36f88088b7a83)
	github.com/sourcegraph/sourcegraph/internal/sentry/sentry.go:135 +0x82
net/http.HandlerFunc.ServeHTTP(0x9b2c6d, {0x6e8e388, 0xc01cab2fc0}, 0x6e21558)
	net/http/server.go:2046 +0x2f
github.com/opentracing-contrib/go-stdlib/nethttp.MiddlewareFunc.func5({0x6e8e388, 0xc01cab2fc0}, 0xc32164f200)
	github.com/opentracing-contrib/[email protected]/nethttp/server.go:119 +0x674
net/http.HandlerFunc.ServeHTTP(0x6eb2340, {0x6e8e388, 0xc01cab2fc0}, 0x6e21558)
	net/http/server.go:2046 +0x2f
github.com/sourcegraph/sourcegraph/internal/trace/ot.MiddlewareWithTracer.func2({0x6e8e388, 0xc01cab2fc0}, 0xc32164f100)
	github.com/sourcegraph/sourcegraph/internal/trace/ot/ot.go:70 +0x376
net/http.HandlerFunc.ServeHTTP(0x0, {0x6e8e388, 0xc01cab2fc0}, 0x466bee)
	net/http/server.go:2046 +0x2f
net/http.serverHandler.ServeHTTP({0xc19cecf2f0}, {0x6e8e388, 0xc01cab2fc0}, 0xc32164f100)
	net/http/server.go:2878 +0x43b
net/http.(*conn).serve(0xc3d1518460, {0x6eb23e8, 0xc001eaa3c0})
	net/http/server.go:1929 +0xb08
created by net/http.(*Server).Serve
	net/http/server.go:3033 +0x4e8

Merge request reports

Loading