diff --git a/internal/api/oidc/introspect.go b/internal/api/oidc/introspect.go index d5716063b6..8cf5100e97 100644 --- a/internal/api/oidc/introspect.go +++ b/internal/api/oidc/introspect.go @@ -25,7 +25,7 @@ func (s *Server) Introspect(ctx context.Context, r *op.Request[op.IntrospectionR } if s.features.TriggerIntrospectionProjections { // Execute all triggers in one concurrent sweep. - ctx = query.TriggerIntrospectionProjections(ctx) + query.TriggerIntrospectionProjections(ctx) } ctx, cancel := context.WithCancel(ctx) @@ -78,8 +78,8 @@ func (s *Server) Introspect(ctx context.Context, r *op.Request[op.IntrospectionR defer func() { if err != nil { s.getLogger(ctx).ErrorContext(ctx, "oidc introspection", "err", err) + resp, err = op.NewResponse(new(oidc.IntrospectionResponse)), nil } - resp, err = op.NewResponse(new(oidc.IntrospectionResponse)), nil }() if err != nil { diff --git a/internal/query/embed/introspection_client_by_id.sql b/internal/query/embed/introspection_client_by_id.sql index b7100246ce..b8c85806b0 100644 --- a/internal/query/embed/introspection_client_by_id.sql +++ b/internal/query/embed/introspection_client_by_id.sql @@ -1,16 +1,16 @@ with config as ( select app_id, client_id, client_secret - from projections.apps5_api_configs + from projections.apps6_api_configs where instance_id = $1 and client_id = $2 union select app_id, client_id, client_secret - from projections.apps5_oidc_configs + from projections.apps6_oidc_configs where instance_id = $1 and client_id = $2 ), keys as ( - select identifier as client_id, json_object_agg(id, public_key) as public_keys + select identifier as client_id, json_object_agg(id, encode(public_key, 'base64')) as public_keys from projections.authn_keys2 where $3 = true -- when argument is false, don't waste time on trying to query for keys. and instance_id = $1 @@ -19,5 +19,5 @@ keys as ( group by identifier ) select config.client_id, config.client_secret, apps.project_id, keys.public_keys from config -join projections.apps5 apps on apps.id = config.app_id +join projections.apps6 apps on apps.id = config.app_id left join keys on keys.client_id = config.client_id; diff --git a/internal/query/introspection.go b/internal/query/introspection.go index da60db07ca..2e22ef78fe 100644 --- a/internal/query/introspection.go +++ b/internal/query/introspection.go @@ -18,8 +18,8 @@ var introspectionTriggerHandlers = append(oidcUserInfoTriggerHandlers, projection.AuthNKeyProjection, ) -func TriggerIntrospectionProjections(ctx context.Context) context.Context { - return triggerBatch(ctx, introspectionTriggerHandlers...) +func TriggerIntrospectionProjections(ctx context.Context) { + triggerBatch(ctx, introspectionTriggerHandlers...) } type IntrospectionClient struct { diff --git a/internal/query/query.go b/internal/query/query.go index e923151aa6..e832d62c55 100644 --- a/internal/query/query.go +++ b/internal/query/query.go @@ -153,22 +153,21 @@ func init() { // triggerBatch calls Trigger on every handler in a seperate Go routine. // The returned context is the context returned by the Trigger that finishes last. -func triggerBatch(ctx context.Context, handlers ...*handler.Handler) context.Context { - ctxChan := make(chan context.Context) +func triggerBatch(ctx context.Context, handlers ...*handler.Handler) { + var wg sync.WaitGroup + wg.Add(len(handlers)) for _, h := range handlers { - go func(ctx context.Context, h *handler.Handler, ctxChan chan<- context.Context) { + go func(ctx context.Context, h *handler.Handler) { name := h.ProjectionName() _, traceSpan := tracing.NewNamedSpan(ctx, fmt.Sprintf("Trigger%s", name)) - newCtx, err := h.Trigger(ctx, handler.WithAwaitRunning()) + _, err := h.Trigger(ctx, handler.WithAwaitRunning()) logging.OnError(err).WithField("projection", name).Debug("trigger failed") traceSpan.EndWithError(err) - ctxChan <- newCtx - }(ctx, h, ctxChan) + + wg.Done() + }(ctx, h) } - for i := 0; i < len(handlers); i++ { - ctx = <-ctxChan - } - return ctx + wg.Wait() } diff --git a/internal/query/user.go b/internal/query/user.go index 6bc556a11d..d7c27c843f 100644 --- a/internal/query/user.go +++ b/internal/query/user.go @@ -706,8 +706,8 @@ func NewUserLoginNameExistsQuery(value string, comparison TextComparison) (Searc ) } -func triggerUserProjections(ctx context.Context) context.Context { - return triggerBatch(ctx, projection.UserProjection, projection.LoginNameProjection) +func triggerUserProjections(ctx context.Context) { + triggerBatch(ctx, projection.UserProjection, projection.LoginNameProjection) } func prepareLoginNamesQuery() (string, []interface{}, error) { diff --git a/internal/query/userinfo.go b/internal/query/userinfo.go index a65420c067..e4682cbdc4 100644 --- a/internal/query/userinfo.go +++ b/internal/query/userinfo.go @@ -22,8 +22,8 @@ var oidcUserInfoTriggerHandlers = []*handler.Handler{ projection.ProjectProjection, } -func TriggerOIDCUserInfoProjections(ctx context.Context) context.Context { - return triggerBatch(ctx, oidcUserInfoTriggerHandlers...) +func TriggerOIDCUserInfoProjections(ctx context.Context) { + triggerBatch(ctx, oidcUserInfoTriggerHandlers...) } //go:embed embed/userinfo_by_id.sql