From 0bf84b77d8040f05da048ebb91ece25327e10ae0 Mon Sep 17 00:00:00 2001 From: Jens L Date: Wed, 20 Dec 2023 00:40:26 +0100 Subject: [PATCH] providers/scim: set timeout based on page and page count (#7941) providers/scim: set better timeouts Signed-off-by: Jens Langhammer --- authentik/providers/scim/clients/__init__.py | 1 + authentik/providers/scim/tasks.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/authentik/providers/scim/clients/__init__.py b/authentik/providers/scim/clients/__init__.py index a57539f67..0e2e573b5 100644 --- a/authentik/providers/scim/clients/__init__.py +++ b/authentik/providers/scim/clients/__init__.py @@ -1,2 +1,3 @@ """SCIM constants""" PAGE_SIZE = 100 +PAGE_TIMEOUT = 60 * 60 * 0.5 # Half an hour diff --git a/authentik/providers/scim/tasks.py b/authentik/providers/scim/tasks.py index f7639c89f..c0c074ea4 100644 --- a/authentik/providers/scim/tasks.py +++ b/authentik/providers/scim/tasks.py @@ -12,7 +12,7 @@ from structlog.stdlib import get_logger from authentik.core.models import Group, User from authentik.events.monitored_tasks import MonitoredTask, TaskResult, TaskResultStatus from authentik.lib.utils.reflection import path_to_class -from authentik.providers.scim.clients import PAGE_SIZE +from authentik.providers.scim.clients import PAGE_SIZE, PAGE_TIMEOUT from authentik.providers.scim.clients.base import SCIMClient from authentik.providers.scim.clients.exceptions import SCIMRequestException, StopSync from authentik.providers.scim.clients.group import SCIMGroupClient @@ -53,6 +53,9 @@ def scim_sync(self: MonitoredTask, provider_pk: int) -> None: LOGGER.debug("Starting SCIM sync") users_paginator = Paginator(provider.get_user_qs(), PAGE_SIZE) groups_paginator = Paginator(provider.get_group_qs(), PAGE_SIZE) + self.soft_time_limit = self.time_limit = ( + users_paginator.count + groups_paginator.count + ) * PAGE_TIMEOUT with allow_join_result(): try: for page in users_paginator.page_range: @@ -69,7 +72,10 @@ def scim_sync(self: MonitoredTask, provider_pk: int) -> None: self.set_status(result) -@CELERY_APP.task() +@CELERY_APP.task( + soft_time_limit=PAGE_TIMEOUT, + task_time_limit=PAGE_TIMEOUT, +) def scim_sync_users(page: int, provider_pk: int): """Sync single or multiple users to SCIM""" messages = []