authgear / authgear-server

Open source alternative to Auth0 / Firebase Auth
https://www.authgear.com
Apache License 2.0
81 stars 37 forks source link

In Admin API, graphql-go library's stack trace of error logs is lost #3538

Open tung2744 opened 9 months ago

tung2744 commented 9 months ago

For example, when the code encounter a crash due to nil pointer dereference, the stacktrace didn't mention where this error occurs.

ERRO[1051] unexpected error when executing GraphQL query  app=my-app error="runtime error: invalid memory address or nil pointer dereference" logger=admin-graphql path="[users]" stack="[log.(*StackHook).Fire at /Users/tung/repo/authgear-server/pkg/util/log/stack_hook.go:23 logrus.LevelHooks.Fire at /Users/tung/.asdf/installs/golang/1.21.4/packages/pkg/mod/github.com/sirupsen/logrus@v1.9.3/hooks.go:28 logrus.(*Entry).fireHooks at /Users/tung/.asdf/installs/golang/1.21.4/packages/pkg/mod/github.com/sirupsen/logrus@v1.9.3/entry.go:280 logrus.(*Entry).log at /Users/tung/.asdf/installs/golang/1.21.4/packages/pkg/mod/github.com/sirupsen/logrus@v1.9.3/entry.go:242 logrus.(*Entry).Log at /Users/tung/.asdf/installs/golang/1.21.4/packages/pkg/mod/github.com/sirupsen/logrus@v1.9.3/entry.go:304 logrus.(*Entry).Error at /Users/tung/.asdf/installs/golang/1.21.4/packages/pkg/mod/github.com/sirupsen/logrus@v1.9.3/entry.go:333 graphqlutil.(*APIErrorExtension).ExecutionDidStart.APIErrorExtension.ExecutionDidStart.func1 at /Users/tung/repo/authgear-server/pkg/util/graphqlutil/api_error.go:57 graphql.handleExtensionsExecutionDidStart.func2.1 at /Users/tung/.asdf/installs/golang/1.21.4/packages/pkg/mod/github.com/graphql-go/graphql@v0.8.1/extensions.go:187 graphql.handleExtensionsExecutionDidStart.func2 at /Users/tung/.asdf/installs/golang/1.21.4/packages/pkg/mod/github.com/graphql-go/graphql@v0.8.1/extensions.go:188 graphql.Execute.func1 at /Users/tung/.asdf/installs/golang/1.21.4/packages/pkg/mod/github.com/graphql-go/graphql@v0.8.1/executor.go:42 graphql.Execute at /Users/tung/.asdf/installs/golang/1.21.4/packages/pkg/mod/github.com/graphql-go/graphql@v0.8.1/executor.go:91 graphql.Do at /Users/tung/.asdf/installs/golang/1.21.4/packages/pkg/mod/github.com/graphql-go/graphql@v0.8.1/graphql.go:108 handler.(*Handler).ContextHandler at /Users/tung/.asdf/installs/golang/1.21.4/packages/pkg/mod/github.com/graphql-go/handler@v0.2.3/handler.go:142 transport.(*GraphQLHandler).ServeHTTP.func1 at /Users/tung/repo/authgear-server/pkg/admin/transport/handler_graphql.go:62 db.(*HookHandle).WithTx at /Users/tung/repo/authgear-server/pkg/lib/infra/db/hook_handle.go:89 transport.(*GraphQLHandler).ServeHTTP at /Users/tung/repo/authgear-server/pkg/admin/transport/handler_graphql.go:47 admin.NewRouter.(*RootProvider).Handler.func7 at /Users/tung/repo/authgear-server/pkg/lib/deps/providers.go:190 http.HandlerFunc.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2136 httputil.CheckContentType.func1.makeCheckContentTypeHandlerFunc.func1 at /Users/tung/repo/authgear-server/pkg/util/httputil/content_type.go:71 http.HandlerFunc.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2136 transport.(*UIParamMiddleware).Handle.func1 at /Users/tung/repo/authgear-server/pkg/admin/transport/ui_param.go:43 http.HandlerFunc.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2136 admin.NewRouter.(*RootProvider).Middleware.func5.1 at /Users/tung/repo/authgear-server/pkg/lib/deps/providers.go:204 http.HandlerFunc.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2136 authz.(*Middleware).Handle.func1 at /Users/tung/repo/authgear-server/pkg/lib/admin/authz/middleware.go:98 http.HandlerFunc.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2136 admin.NewRouter.(*RootProvider).Middleware.func4.1 at /Users/tung/repo/authgear-server/pkg/lib/deps/providers.go:204 http.HandlerFunc.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2136 deps.(*RequestMiddleware).Handle.func1 at /Users/tung/repo/authgear-server/pkg/lib/deps/middleware_request.go:56 http.HandlerFunc.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2136 httputil.NoStore.func1 at /Users/tung/repo/authgear-server/pkg/util/httputil/no_store.go:12 http.HandlerFunc.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2136 httputil.(*StaticCSPHeader).Handle.StaticCSPHeader.Handle.func1 at /Users/tung/repo/authgear-server/pkg/util/httputil/static_csp_header.go:19 http.HandlerFunc.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2136 httputil.StaticSecurityHeaders.func1 at /Users/tung/repo/authgear-server/pkg/util/httputil/static_security_headers.go:10 http.HandlerFunc.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2136 middleware.(*SentryMiddleware).Handle.func1 at /Users/tung/repo/authgear-server/pkg/lib/infra/middleware/sentry.go:22 http.HandlerFunc.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2136 middleware.(*BodyLimitMiddleware).Handle.func1 at /Users/tung/repo/authgear-server/pkg/lib/infra/middleware/body_limit.go:16 http.HandlerFunc.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2136 middleware.(*PanicMiddleware).Handle.func1 at /Users/tung/repo/authgear-server/pkg/lib/infra/middleware/panic.go:62 http.HandlerFunc.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2136 httproute.(*Router).Add.(*Router).Handler.func1 at /Users/tung/.asdf/installs/golang/1.21.4/packages/pkg/mod/github.com/julienschmidt/httprouter@v1.3.0/router.go:275 httprouter.(*Router).ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/packages/pkg/mod/github.com/julienschmidt/httprouter@v1.3.0/router.go:387 httproute.(*Router).ServeHTTP at /Users/tung/repo/authgear-server/pkg/util/httproute/httproute.go:85 http.serverHandler.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2938 http.(*conn).serve at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2009]"
tung2744 commented 8 months ago

It looks like the stack trace is lost when the library handles the panic, so not possible to log the correct stack trace.