diff --git a/pkg/services/contexthandler/contexthandler.go b/pkg/services/contexthandler/contexthandler.go index b31a0e8b72a..aad500e1451 100644 --- a/pkg/services/contexthandler/contexthandler.go +++ b/pkg/services/contexthandler/contexthandler.go @@ -350,11 +350,17 @@ func (h *ContextHandler) initContextWithAPIKey(reqContext *models.ReqContext) bo return true } - // update api_key last used date - if err := h.apiKeyService.UpdateAPIKeyLastUsedDate(reqContext.Req.Context(), apikey.Id); err != nil { - reqContext.JsonApiErr(http.StatusInternalServerError, InvalidAPIKey, errKey) - return true - } + // non-blocking update api_key last used date + go func(id int64) { + defer func() { + if err := recover(); err != nil { + reqContext.Logger.Error("api key authentication panic", "err", err) + } + }() + if err := h.apiKeyService.UpdateAPIKeyLastUsedDate(context.Background(), id); err != nil { + reqContext.Logger.Warn("failed to update last use date for api key", "id", id) + } + }(apikey.Id) if apikey.ServiceAccountId == nil || *apikey.ServiceAccountId < 1 { //There is no service account attached to the apikey // Use the old APIkey method. This provides backwards compatibility.