Repository: goauthentik/authentik

Issue:
If Authentik can't sync to LDAP, `authentik.root.celery` will use all available CPU cores until worker is restarted
**Describe the bug**

If your LDAP settings under "Federation & Social login" are incorrect, leading to a sync error, CPU usage will skyrocket to use all available cores. Here's the error in the LDAP Federation settings:

```
Sync status
ldap_sync:lldap:user
Task finished with errors
SoftTimeLimitExceeded()
ldap_sync:lldap:group
Task finished with errors
SoftTimeLimitExceeded()
ldap_sync:lldap:membership
Task finished with errors
SoftTimeLimitExceeded()
```

**To Reproduce**
Steps to reproduce the behavior:

1. Go to 'Admin Interface'
2. Click on 'Directory', 'Federation & Social login'
3. Create a new LDAP source
4. Enter a new LDAP with some error in the settings
5. Wait for next sync task to be scheduled (here it happens every 2h, but once the error happens once, CPU usage does not come back to normal ever again, unless container is restarted).

**Expected behavior**

To not use all available CPU cores.

**Screenshots**

<img width="1392" alt="Screenshot 2023-06-28 at 11 29 35" src="https://github.com/goauthentik/authentik/assets/2992/b9669879-1801-4e9a-bab6-447232a80ac8">

In this image, first CPU was limited to 3 cores, then I changed the limits every time. The ceil here is always the limit. Every time the usage goes down is only because I have restarted the containers. CPU usage never goes down by itself, even though the logs only show this kind of activity every 2 hours.

**Logs**

The full 500+ log lines in the timeframe of less than a minute and a half are too long to post here. Here's a 10s timeframe only:

```
2023-06-28T06:40:02.913383144+02:00 {"event": "Soft time limit (7200s) exceeded for authentik.sources.ldap.tasks.ldap_sync[a37ed240-4526-412c-a0b4-4dcd9c0bcc4f]", "level": "warning", "logger": "celery.worker.request", "timestamp": 1687927202.9131446}
2023-06-28T06:40:02.976883365+02:00 {"action": "system_task_exception", "client_ip": null, "context": {"message": "Task ldap_sync encountered an error: Traceback (most recent call last):\n  File \"/usr/local/lib/python3.11/site-packages/celery/app/trace.py\", line 451, in trace_task\n    R = retval = fun(*args, **kwargs)\n                 ^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/local/lib/python3.11/site-packages/celery/app/trace.py\", line 734, in __protected_call__\n    return self.run(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/authentik/sources/ldap/tasks.py\", line 49, in ldap_sync\n    sync_inst = sync(source)\n                ^^^^^^^^^^^^\n  File \"/authentik/sources/ldap/sync/base.py\", line 28, in __init__\n    self._connection = source.connection()\n                       ^^^^^^^^^^^^^^^^^^^\n  File \"/authentik/sources/ldap/models.py\", line 148, in connection\n    connection.bind()\n  File \"/usr/local/lib/python3.11/site-packages/ldap3/core/connection.py\", line 589, in bind\n    self.open(read_server_info=False)\n  File \"/usr/local/lib/python3.11/site-packages/ldap3/strategy/sync.py\", line 57, in open\n    BaseStrategy.open(self, reset_usage, read_server_info)\n  File \"/usr/local/lib/python3.11/site-packages/ldap3/strategy/base.py\", line 122, in open\n    new_server = self.connection.server_pool.get_server(self.connection)  # get a server from the server_pool if available\n                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/local/lib/python3.11/site-packages/ldap3/core/pooling.py\", line 317, in get_server\n    return self.pool_states[connection].get_server()\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/local/lib/python3.11/site-packages/ldap3/core/pooling.py\", line 97, in get_server\n    self.last_used_server = self.find_active_random_server()\n                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/local/lib/python3.11/site-packages/ldap3/core/pooling.py\", line 122, in find_active_random_server\n    server_state = temp_list.pop(randint(0, len(temp_list) - 1))\n                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/local/lib/python3.11/site-packages/billiard/pool.py\", line 229, in soft_timeout_sighandler\n    raise SoftTimeLimitExceeded()\nbilliard.exceptions.SoftTimeLimitExceeded: SoftTimeLimitExceeded()"}, "event": "Created Event", "level": "info", "logger": "authentik.events.models", "pid": 1022, "task_id": "task-a37ed2404526412ca0b44dcd9c0bcc4f", "timestamp": "2023-06-28T04:40:02.976690", "user": {}}
2023-06-28T06:40:02.982130278+02:00 {"event": "Task published", "level": "info", "logger": "authentik.root.celery", "pid": 1022, "task_id": "742faba3-dad0-4015-8c4e-8bc186c8ccac", "task_name": "authentik.events.tasks.event_notification_handler", "timestamp": "2023-06-28T04:40:02.982007"}
2023-06-28T06:40:02.982312600+02:00 {"event": "Task failure", "exc": "SoftTimeLimitExceeded()", "level": "warning", "logger": "authentik.root.celery", "pid": 1022, "task_id": "task-a37ed2404526412ca0b44dcd9c0bcc4f", "timestamp": "2023-06-28T04:40:02.982230"}
2023-06-28T06:40:02.982471846+02:00 {"event": "Task authentik.sources.ldap.tasks.ldap_sync[a37ed240-4526-412c-a0b4-4dcd9c0bcc4f] raised unexpected: SoftTimeLimitExceeded()", "exc_info": ["<class 'billiard.exceptions.SoftTimeLimitExceeded'>", "SoftTimeLimitExceeded()", "<billiard.einfo.Traceback object at 0x7fcb32c61550>"], "level": "error", "logger": "celery.app.trace", "timestamp": 1687927202.9824204}
2023-06-28T06:40:03.001243050+02:00 {"event": "Soft time limit (7200s) exceeded for authentik.sources.ldap.tasks.ldap_sync[66602233-bc8c-4cf0-a56d-f6d3482995a9]", "level": "warning", "logger": "celery.worker.request", "timestamp": 1687927203.001077}
2023-06-28T06:40:03.068965766+02:00 {"event": "Task finished", "level": "info", "logger": "authentik.root.celery", "pid": 1022, "state": "FAILURE", "task_id": "a37ed240-4526-412c-a0b4-4dcd9c0bcc4f", "task_name": "ldap_sync", "timestamp": "2023-06-28T04:40:03.068644"}
2023-06-28T06:40:03.079585704+02:00 {"action": "system_task_exception", "client_ip": null, "context": {"message": "Task ldap_sync encountered an error: Traceback (most recent call last):\n  File \"/usr/local/lib/python3.11/site-packages/celery/app/trace.py\", line 451, in trace_task\n    R = retval = fun(*args, **kwargs)\n                 ^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/local/lib/python3.11/site-packages/celery/app/trace.py\", line 734, in __protected_call__\n    return self.run(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/authentik/sources/ldap/tasks.py\", line 49, in ldap_sync\n    sync_inst = sync(source)\n                ^^^^^^^^^^^^\n  File \"/authentik/sources/ldap/sync/base.py\", line 28, in __init__\n    self._connection = source.connection()\n                       ^^^^^^^^^^^^^^^^^^^\n  File \"/authentik/sources/ldap/models.py\", line 148, in connection\n    connection.bind()\n  File \"/usr/local/lib/python3.11/site-packages/ldap3/core/connection.py\", line 589, in bind\n    self.open(read_server_info=False)\n  File \"/usr/local/lib/python3.11/site-packages/ldap3/strategy/sync.py\", line 57, in open\n    BaseStrategy.open(self, reset_usage, read_server_info)\n  File \"/usr/local/lib/python3.11/site-packages/ldap3/strategy/base.py\", line 122, in open\n    new_server = self.connection.server_pool.get_server(self.connection)  # get a server from the server_pool if available\n                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/local/lib/python3.11/site-packages/ldap3/core/pooling.py\", line 317, in get_server\n    return self.pool_states[connection].get_server()\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/local/lib/python3.11/site-packages/ldap3/core/pooling.py\", line 97, in get_server\n    self.last_used_server = self.find_active_random_server()\n                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/local/lib/python3.11/site-packages/ldap3/core/pooling.py\", line 116, in find_active_random_server\n    if log_enabled(NETWORK):\n       ^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/local/lib/python3.11/site-packages/ldap3/utils/log.py\", line 121, in log_enabled\n    def log_enabled(detail):\n  File \"/usr/local/lib/python3.11/site-packages/billiard/pool.py\", line 229, in soft_timeout_sighandler\n    raise SoftTimeLimitExceeded()\nbilliard.exceptions.SoftTimeLimitExceeded: SoftTimeLimitExceeded()"}, "event": "Created Event", "level": "info", "logger": "authentik.events.models", "pid": 1023, "task_id": "task-66602233bc8c4cf0a56df6d3482995a9", "timestamp": "2023-06-28T04:40:03.079127", "user": {}}
2023-06-28T06:40:03.172788663+02:00 {"event": "Task published", "level": "info", "logger": "authentik.root.celery", "pid": 1023, "task_id": "7b0a93f2-7058-4637-a2b2-a08d14ab6200", "task_name": "authentik.events.tasks.event_notification_handler", "timestamp": "2023-06-28T04:40:03.172539"}
2023-06-28T06:40:03.173281683+02:00 {"event": "Task failure", "exc": "SoftTimeLimitExceeded()", "level": "warning", "logger": "authentik.root.celery", "pid": 1023, "task_id": "task-66602233bc8c4cf0a56df6d3482995a9", "timestamp": "2023-06-28T04:40:03.172994"}
2023-06-28T06:40:03.173662903+02:00 {"event": "Task authentik.sources.ldap.tasks.ldap_sync[66602233-bc8c-4cf0-a56d-f6d3482995a9] raised unexpected: SoftTimeLimitExceeded()", "exc_info": ["<class 'billiard.exceptions.SoftTimeLimitExceeded'>", "SoftTimeLimitExceeded()", "<billiard.einfo.Traceback object at 0x7fcb32c62250>"], "level": "error", "logger": "celery.app.trace", "timestamp": 1687927203.173544}
2023-06-28T06:40:03.174251579+02:00 {"event": "Task finished", "level": "info", "logger": "authentik.root.celery", "pid": 1023, "state": "FAILURE", "task_id": "66602233-bc8c-4cf0-a56d-f6d3482995a9", "task_name": "ldap_sync", "timestamp": "2023-06-28T04:40:03.174106"}
2023-06-28T06:40:04.471213392+02:00 {"event": "Task started", "level": "info", "logger": "authentik.root.celery", "pid": 1027, "task_id": "83064485-d154-485f-97d7-ff5e45bee43f", "task_name": "event_trigger_handler", "timestamp": "2023-06-28T04:40:04.470652"}
2023-06-28T06:40:04.573130747+02:00 {"event": "Task finished", "level": "info", "logger": "authentik.root.celery", "pid": 1027, "state": "SUCCESS", "task_id": "83064485-d154-485f-97d7-ff5e45bee43f", "task_name": "event_trigger_handler", "timestamp": "2023-06-28T04:40:04.572817"}
2023-06-28T06:40:04.584256897+02:00 {"event": "Task started", "level": "info", "logger": "authentik.root.celery", "pid": 1028, "task_id": "195bc043-e10c-4ea4-a24f-d5792c110430", "task_name": "event_trigger_handler", "timestamp": "2023-06-28T04:40:04.583688"}
2023-06-28T06:40:04.780775134+02:00 {"event": "Task finished", "level": "info", "logger": "authentik.root.celery", "pid": 1028, "state": "SUCCESS", "task_id": "195bc043-e10c-4ea4-a24f-d5792c110430", "task_name": "event_trigger_handler", "timestamp": "2023-06-28T04:40:04.780636"}
2023-06-28T06:40:05.784130961+02:00 {"event": "Task started", "level": "info", "logger": "authentik.root.celery", "pid": 1029, "task_id": "8eb48768-c5df-4693-aec8-6accb0118ca5", "task_name": "event_trigger_handler", "timestamp": "2023-06-28T04:40:05.783573"}
2023-06-28T06:40:05.979455552+02:00 {"event": "Task started", "level": "info", "logger": "authentik.root.celery", "pid": 1030, "task_id": "3315af94-c6ac-497d-9c60-94250e4fac6f", "task_name": "event_trigger_handler", "timestamp": "2023-06-28T04:40:05.979195"}
2023-06-28T06:40:05.982517377+02:00 {"event": "Task finished", "level": "info", "logger": "authentik.root.celery", "pid": 1029, "state": "SUCCESS", "task_id": "8eb48768-c5df-4693-aec8-6accb0118ca5", "task_name": "event_trigger_handler", "timestamp": "2023-06-28T04:40:05.982336"}
2023-06-28T06:40:06.169176729+02:00 {"event": "Task finished", "level": "info", "logger": "authentik.root.celery", "pid": 1030, "state": "SUCCESS", "task_id": "3315af94-c6ac-497d-9c60-94250e4fac6f", "task_name": "event_trigger_handler", "timestamp": "2023-06-28T04:40:06.168836"}
2023-06-28T06:40:07.291254283+02:00 {"event": "Task started", "level": "info", "logger": "authentik.root.celery", "pid": 1031, "task_id": "c4008af0-381d-4af0-a903-f3a23694f82b", "task_name": "clean_expired_models", "timestamp": "2023-06-28T04:40:07.290960"}
2023-06-28T06:40:07.474821105+02:00 {"event": "Task started", "level": "info", "logger": "authentik.root.celery", "pid": 1032, "task_id": "f84646e3-50b9-4f70-9b96-7c80cde14dce", "task_name": "save_reputation", "timestamp": "2023-06-28T04:40:07.474124"}
2023-06-28T06:40:07.483025662+02:00 {"event": "Task finished", "level": "info", "logger": "authentik.root.celery", "pid": 1032, "state": "SUCCESS", "task_id": "f84646e3-50b9-4f70-9b96-7c80cde14dce", "task_name": "save_reputation", "timestamp": "2023-06-28T04:40:07.482338"}
2023-06-28T06:40:07.570628465+02:00 {"event": "Task finished", "level": "info", "logger": "authentik.root.celery", "pid": 1031, "state": "SUCCESS", "task_id": "c4008af0-381d-4af0-a903-f3a23694f82b", "task_name": "clean_expired_models", "timestamp": "2023-06-28T04:40:07.570334"}
2023-06-28T06:40:08.186019955+02:00 {"event": "Task started", "level": "info", "logger": "authentik.root.celery", "pid": 1033, "task_id": "bc8847d5-e0af-450c-9585-aab895021d6d", "task_name": "scim_signal_direct", "timestamp": "2023-06-28T04:40:08.185396"}
2023-06-28T06:40:08.284620892+02:00 {"event": "Task finished", "level": "info", "logger": "authentik.root.celery", "pid": 1033, "state": "SUCCESS", "task_id": "bc8847d5-e0af-450c-9585-aab895021d6d", "task_name": "scim_signal_direct", "timestamp": "2023-06-28T04:40:08.284382"}
2023-06-28T06:40:09.391287797+02:00 {"event": "Task started", "level": "info", "logger": "authentik.root.celery", "pid": 1034, "task_id": "2e36088d-aaff-4a3b-b14b-7ce0c73fcdba", "task_name": "scim_signal_direct", "timestamp": "2023-06-28T04:40:09.391046"}
2023-06-28T06:40:09.481291368+02:00 {"event": "Task finished", "level": "info", "logger": "authentik.root.celery", "pid": 1034, "state": "SUCCESS", "task_id": "2e36088d-aaff-4a3b-b14b-7ce0c73fcdba", "task_name": "scim_signal_direct", "timestamp": "2023-06-28T04:40:09.481161"}
2023-06-28T06:40:09.574327029+02:00 {"event": "Task started", "level": "info", "logger": "authentik.root.celery", "pid": 1035, "task_id": "e94a3e58-cb6e-4107-bdf7-0b9bf3ed3c38", "task_name": "scim_signal_direct", "timestamp": "2023-06-28T04:40:09.574011"}
2023-06-28T06:40:09.584753706+02:00 {"event": "Task finished", "level": "info", "logger": "authentik.root.celery", "pid": 1035, "state": "SUCCESS", "task_id": "e94a3e58-cb6e-4107-bdf7-0b9bf3ed3c38", "task_name": "scim_signal_direct", "timestamp": "2023-06-28T04:40:09.584565"}
2023-06-28T06:40:10.476668483+02:00 {"event": "Soft time limit (7200s) exceeded for authentik.sources.ldap.tasks.ldap_sync[e31088f9-ce74-4363-a602-930d21c33371]", "level": "warning", "logger": "celery.worker.request", "timestamp": 1687927210.476222}
2023-06-28T06:40:10.478570303+02:00 {"event": "Task started", "level": "info", "logger": "authentik.root.celery", "pid": 1036, "task_id": "ca986c71-110a-4e43-a5bb-e208bc24ef83", "task_name": "scim_signal_direct", "timestamp": "2023-06-28T04:40:10.477982"}
2023-06-28T06:40:10.483391777+02:00 {"action": "system_task_exception", "client_ip": null, "context": {"message": "Task ldap_sync encountered an error: Traceback (most recent call last):\n  File \"/usr/local/lib/python3.11/site-packages/celery/app/trace.py\", line 451, in trace_task\n    R = retval = fun(*args, **kwargs)\n                 ^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/local/lib/python3.11/site-packages/celery/app/trace.py\", line 734, in __protected_call__\n    return self.run(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/authentik/sources/ldap/tasks.py\", line 49, in ldap_sync\n    sync_inst = sync(source)\n                ^^^^^^^^^^^^\n  File \"/authentik/sources/ldap/sync/membership.py\", line 19, in __init__\n    super().__init__(source)\n  File \"/authentik/sources/ldap/sync/base.py\", line 28, in __init__\n    self._connection = source.connection()\n                       ^^^^^^^^^^^^^^^^^^^\n  File \"/authentik/sources/ldap/models.py\", line 148, in connection\n    connection.bind()\n  File \"/usr/local/lib/python3.11/site-packages/ldap3/core/connection.py\", line 589, in bind\n    self.open(read_server_info=False)\n  File \"/usr/local/lib/python3.11/site-packages/ldap3/strategy/sync.py\", line 57, in open\n    BaseStrategy.open(self, reset_usage, read_server_info)\n  File \"/usr/local/lib/python3.11/site-packages/ldap3/strategy/base.py\", line 122, in open\n    new_server = self.connection.server_pool.get_server(self.connection)  # get a server from the server_pool if available\n                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/local/lib/python3.11/site-packages/ldap3/core/pooling.py\", line 317, in get_server\n    return self.pool_states[connection].get_server()\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/local/lib/python3.11/site-packages/ldap3/core/pooling.py\", line 97, in get_server\n    self.last_used_server = self.find_active_random_server()\n                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/local/lib/python3.11/site-packages/ldap3/core/pooling.py\", line 122, in find_active_random_server\n    server_state = temp_list.pop(randint(0, len(temp_list) - 1))\n                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/local/lib/python3.11/random.py\", line 358, in randint\n    def randint(self, a, b):\n  File \"/usr/local/lib/python3.11/site-packages/billiard/pool.py\", line 229, in soft_timeout_sighandler\n    raise SoftTimeLimitExceeded()\nbilliard.exceptions.SoftTimeLimitExceeded: SoftTimeLimitExceeded()"}, "event": "Created Event", "level": "info", "logger": "authentik.events.models", "pid": 1026, "task_id": "task-e31088f9ce744363a602930d21c33371", "timestamp": "2023-06-28T04:40:10.483195", "user": {}}
2023-06-28T06:40:10.573003422+02:00 {"event": "Task finished", "level": "info", "logger": "authentik.root.celery", "pid": 1036, "state": "SUCCESS", "task_id": "ca986c71-110a-4e43-a5bb-e208bc24ef83", "task_name": "scim_signal_direct", "timestamp": "2023-06-28T04:40:10.572554"}
2023-06-28T06:40:10.575974480+02:00 {"event": "Task published", "level": "info", "logger": "authentik.root.celery", "pid": 1026, "task_id": "fba1f987-549a-4abc-a76c-e235ab0ea109", "task_name": "authentik.events.tasks.event_notification_handler", "timestamp": "2023-06-28T04:40:10.575632"}
2023-06-28T06:40:10.576604624+02:00 {"event": "Task failure", "exc": "SoftTimeLimitExceeded()", "level": "warning", "logger": "authentik.root.celery", "pid": 1026, "task_id": "task-e31088f9ce744363a602930d21c33371", "timestamp": "2023-06-28T04:40:10.576270"}
2023-06-28T06:40:10.577210890+02:00 {"event": "Task authentik.sources.ldap.tasks.ldap_sync[e31088f9-ce74-4363-a602-930d21c33371] raised unexpected: SoftTimeLimitExceeded()", "exc_info": ["<class 'billiard.exceptions.SoftTimeLimitExceeded'>", "SoftTimeLimitExceeded()", "<billiard.einfo.Traceback object at 0x7fcb32c61290>"], "level": "error", "logger": "celery.app.trace", "timestamp": 1687927210.5769174}
2023-06-28T06:40:10.578315914+02:00 {"event": "Task finished", "level": "info", "logger": "authentik.root.celery", "pid": 1026, "state": "FAILURE", "task_id": "e31088f9-ce74-4363-a602-930d21c33371", "task_name": "ldap_sync", "timestamp": "2023-06-28T04:40:10.577965"}
2023-06-28T06:40:10.683581058+02:00 {"event": "Task started", "level": "info", "logger": "authentik.root.celery", "pid": 1037, "task_id": "8eb48768-c5df-4693-aec8-6accb0118ca5", "task_name": "event_trigger_handler", "timestamp": "2023-06-28T04:40:10.683054"}
2023-06-28T06:40:10.792053301+02:00 {"event": "Task finished", "level": "info", "logger": "authentik.root.celery", "pid": 1037, "state": "SUCCESS", "task_id": "8eb48768-c5df-4693-aec8-6accb0118ca5", "task_name": "event_trigger_handler", "timestamp": "2023-06-28T04:40:10.791892"}
2023-06-28T06:40:11.210389963+02:00 {"event": "Task started", "level": "info", "logger": "authentik.root.celery", "pid": 1038, "task_id": "cd1f211a-b695-44cb-8a8c-bfafbb471db4", "task_name": "scim_signal_direct", "timestamp": "2023-06-28T04:40:11.210148"}
2023-06-28T06:40:11.288864766+02:00 {"event": "Task finished", "level": "info", "logger": "authentik.root.celery", "pid": 1038, "state": "SUCCESS", "task_id": "cd1f211a-b695-44cb-8a8c-bfafbb471db4", "task_name": "scim_signal_direct", "timestamp": "2023-06-28T04:40:11.288616"}
2023-06-28T06:40:11.369842853+02:00 {"event": "Task started", "level": "info", "logger": "authentik.root.celery", "pid": 1039, "task_id": "2e36088d-aaff-4a3b-b14b-7ce0c73fcdba", "task_name": "scim_signal_direct", "timestamp": "2023-06-28T04:40:11.369221"}
2023-06-28T06:40:11.395123919+02:00 {"event": "Task finished", "level": "info", "logger": "authentik.root.celery", "pid": 1039, "state": "SUCCESS", "task_id": "2e36088d-aaff-4a3b-b14b-7ce0c73fcdba", "task_name": "scim_signal_direct", "timestamp": "2023-06-28T04:40:11.394797"}
2023-06-28T06:40:11.894948732+02:00 {"event": "Task started", "level": "info", "logger": "authentik.root.celery", "pid": 1040, "task_id": "4b0f820b-8c12-49a7-88f4-9b175f7b7e09", "task_name": "clean_temporary_users", "timestamp": "2023-06-28T04:40:11.894625"}
2023-06-28T06:40:11.977682087+02:00 {"event": "Task finished", "level": "info", "logger": "authentik.root.celery", "pid": 1040, "state": "SUCCESS", "task_id": "4b0f820b-8c12-49a7-88f4-9b175f7b7e09", "task_name": "clean_temporary_users", "timestamp": "2023-06-28T04:40:11.977276"}
2023-06-28T06:40:12.211923190+02:00 {"event": "Task started", "level": "info", "logger": "authentik.root.celery", "pid": 1041, "task_id": "83064485-d154-485f-97d7-ff5e45bee43f", "task_name": "event_trigger_handler", "timestamp": "2023-06-28T04:40:12.211670"}
2023-06-28T06:40:12.285860775+02:00 {"event": "Task finished", "level": "info", "logger": "authentik.root.celery", "pid": 1041, "state": "SUCCESS", "task_id": "83064485-d154-485f-97d7-ff5e45bee43f", "task_name": "event_trigger_handler", "timestamp": "2023-06-28T04:40:12.285488"}
2023-06-28T06:40:12.290829156+02:00 {"event": "Task started", "level": "info", "logger": "authentik.root.celery", "pid": 1042, "task_id": "e94a3e58-cb6e-4107-bdf7-0b9bf3ed3c38", "task_name": "scim_signal_direct", "timestamp": "2023-06-28T04:40:12.290535"}
2023-06-28T06:40:12.394954453+02:00 {"event": "Task finished", "level": "info", "logger": "authentik.root.celery", "pid": 1042, "state": "SUCCESS", "task_id": "e94a3e58-cb6e-4107-bdf7-0b9bf3ed3c38", "task_name": "scim_signal_direct", "timestamp": "2023-06-28T04:40:12.394573"}
```

**Version and Deployment**

-   authentik version: 2023.5.4
-   Deployment: helm


Discussion:

Resolving patch:
diff --git a/authentik/sources/ldap/models.py b/authentik/sources/ldap/models.py
--- a/authentik/sources/ldap/models.py
+++ b/authentik/sources/ldap/models.py
@@ -151,7 +151,7 @@ def server(self, **kwargs) -> Server:
                 servers.append(Server(server, **server_kwargs))
         else:
             servers = [Server(self.server_uri, **server_kwargs)]
-        return ServerPool(servers, RANDOM, active=True, exhaust=True)
+        return ServerPool(servers, RANDOM, active=5, exhaust=True)
 
     def connection(
         self, server_kwargs: Optional[dict] = None, connection_kwargs: Optional[dict] = None


Test patch: