diff --git a/backend/internal/repository/api_key_repo.go b/backend/internal/repository/api_key_repo.go index d69a8bf0c9..638eec52f1 100644 --- a/backend/internal/repository/api_key_repo.go +++ b/backend/internal/repository/api_key_repo.go @@ -462,7 +462,7 @@ func (r *apiKeyRepository) attachLastUsedIPs(ctx context.Context, keys []service return nil } -func (r *apiKeyRepository) latestUsageLogIPs(ctx context.Context, apiKeyIDs []int64) (map[int64]string, error) { +func (r *apiKeyRepository) latestUsageLogIPs(ctx context.Context, apiKeyIDs []int64) (result map[int64]string, err error) { if len(apiKeyIDs) == 0 || r.sql == nil { return map[int64]string{}, nil } @@ -472,7 +472,11 @@ func (r *apiKeyRepository) latestUsageLogIPs(ctx context.Context, apiKeyIDs []in if err != nil { return nil, err } - defer rows.Close() + defer func() { + if closeErr := rows.Close(); closeErr != nil && err == nil { + err = closeErr + } + }() out := make(map[int64]string, len(apiKeyIDs)) for rows.Next() {